Skip to content

Commit

Permalink
Fix NPE when coercing nullable vestion (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrooo committed Oct 9, 2023
1 parent 23c6e26 commit bf58e56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit bf58e56

Please sign in to comment.