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

Fix NPE when coercing nullable version #186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/semver4j/Semver.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ public static Semver parse(@Nullable final String version) {
*/
@Nullable
public static Semver coerce(@Nullable final String version) {
if (version == null) {
return null;
}

Semver semver = parse(version);
if (semver != null) {
return semver;
}

String coerce = Coerce.coerce(version);
return parse(coerce);
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/semver4j/SemverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,15 @@ static Stream<Arguments> coerceVersions() {
);
}

@Test
void shouldReturnNullWhenTryCoerceNullableVersion() {
//when
Semver semver = coerce(null);

//then
assertThat(semver).isNull();
}

@Test
void shouldCreateSemverWithHyphenInBuildSection() {
//when
Expand Down