Skip to content

Commit d0ce1ab

Browse files
authored
fix: check that numeric value exists (#12042)
Check that a value exists for buildIdentifier before parsing integer. Fixes #12041
1 parent 222a793 commit d0ce1ab

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendVersion.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ private int compareBuildIdentifier(FrontendVersion other) {
338338
return thisMatcher.group(1)
339339
.compareToIgnoreCase(otherMatcher.group(1));
340340
}
341+
// if one or both are missing numeric value do not parse int
342+
if (thisMatcher.group(2).isEmpty()
343+
|| otherMatcher.group(2).isEmpty()) {
344+
return buildIdentifier
345+
.compareToIgnoreCase(other.buildIdentifier);
346+
}
341347
return Integer.parseInt(thisMatcher.group(2))
342348
- Integer.parseInt(otherMatcher.group(2));
343349
}

flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendVersionTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55

6+
import static com.helger.commons.mock.CommonsAssert.assertEquals;
67
import static org.junit.Assert.assertFalse;
78
import static org.junit.Assert.assertTrue;
89

@@ -77,6 +78,18 @@ public void testIsEqualTo() {
7778
fromString.isEqualTo(fromConstructor));
7879
}
7980

81+
@Test // #12041
82+
public void testSimilarBuildIdentifiers() {
83+
FrontendVersion version = new FrontendVersion("1.1.1-SNAPSHOT");
84+
FrontendVersion equals = new FrontendVersion("1.1.1-SNAPSHOT");
85+
86+
assertTrue("Versions be the same", version.isEqualTo(equals));
87+
assertFalse("Version should not be older", version.isOlderThan(equals));
88+
assertEquals("Versions should not have a difference", 0,
89+
version.compareTo(equals));
90+
assertFalse("Version should not be newer", version.isNewerThan(equals));
91+
}
92+
8093
@Test(expected = NumberFormatException.class)
8194
public void faultyStringVersion_throwsException() {
8295
new FrontendVersion("12.0b.1");

0 commit comments

Comments
 (0)