Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes NPE in RequestRouting#canonicalize() #1072

Merged
merged 1 commit into from
Sep 30, 2019
Merged

Fixes NPE in RequestRouting#canonicalize() #1072

merged 1 commit into from
Sep 30, 2019

Conversation

ljnelson
Copy link
Member

Signed-off-by: Laird Nelson laird.nelson@oracle.com

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
@ljnelson ljnelson added bug Something isn't working webserver P1 labels Sep 29, 2019
@ljnelson ljnelson self-assigned this Sep 29, 2019
@ljnelson ljnelson added this to In Progress in Backlog Sep 29, 2019
@ljnelson
Copy link
Member Author

This PR makes the RequestRouting#canonicalize(String) method handle null and empty inputs in an effort to solve one of the issues brought up in #1069.

result = p.substring(0, p.length() - 1);
}
if (result.isEmpty()) {
String result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  • Should this not have a unit test to avoid issues going forward?
  • Any reason why not a more fail-fast approach which is easier to read:
    private static String canonicalize(String p) {
        if (p == null || p.isEmpty() || p.equals("/")) {
            return "/";
        }
        int lastCharIndex = p.length() - 1;
        if (p.charAt(lastCharIndex) == '/') {
            return p.substring(0, lastCharIndex);
        }
        return p;
    }

I'm interested to know what the benefit is of indenting more or delaying the return of the method when you already know the result.

@ljnelson ljnelson merged commit 720ca1d into helidon-io:master Sep 30, 2019
Backlog automation moved this from In Progress to Closed Sep 30, 2019
@ljnelson ljnelson deleted the issue-1069 branch September 30, 2019 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 webserver
Projects
Backlog
  
Closed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants