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

Marking the input version as @Nullable is incorrect. #184

Closed
piotrooo opened this issue Oct 4, 2023 · 5 comments · Fixed by #186
Closed

Marking the input version as @Nullable is incorrect. #184

piotrooo opened this issue Oct 4, 2023 · 5 comments · Fixed by #186
Assignees
Labels
bug Something isn't working

Comments

@piotrooo
Copy link
Member

piotrooo commented Oct 4, 2023

If you pass in null to this method, it throws a NullPointerException as it fails to create a regex matcher:

java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null
	at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1769)
	at java.base/java.util.regex.Matcher.reset(Matcher.java:415)
	at java.base/java.util.regex.Matcher.<init>(Matcher.java:252)
	at java.base/java.util.regex.Pattern.matcher(Pattern.java:1134)
	at org.semver4j.internal.Coerce.coerce(Coerce.java:20)
	at org.semver4j.Semver.coerce(Semver.java:89)

Originally posted by @NielsDoucet in #177 (comment)

@piotrooo piotrooo added the bug Something isn't working label Oct 4, 2023
@DIG-
Copy link
Contributor

DIG- commented Oct 4, 2023

There is two ways to resolve:

  • Mark param as NotNull
  • Return null if null

@piotrooo
Copy link
Member Author

piotrooo commented Oct 4, 2023

I thought about returning null when parameter is null. There is no possibility for coercing version on nullable - it's impossible.

@NielsDoucet
Copy link

https://github.com/semver4j/semver4j/blob/main/src/test/java/org/semver4j/SemverTest.java#L743
I also noticed that there wasn't a test for these edge cases (like null and an empty string).

@piotrooo
Copy link
Member Author

piotrooo commented Oct 4, 2023

This's a major oversight...

@piotrooo piotrooo self-assigned this Oct 9, 2023
@piotrooo piotrooo linked a pull request Oct 9, 2023 that will close this issue
@piotrooo
Copy link
Member Author

piotrooo commented Oct 9, 2023

Fixed in v5.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants