diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendVersion.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendVersion.java index 1b7d2300643..c6c7ddb15dd 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendVersion.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendVersion.java @@ -338,6 +338,12 @@ private int compareBuildIdentifier(FrontendVersion other) { return thisMatcher.group(1) .compareToIgnoreCase(otherMatcher.group(1)); } + // if one or both are missing numeric value do not parse int + if (thisMatcher.group(2).isEmpty() + || otherMatcher.group(2).isEmpty()) { + return buildIdentifier + .compareToIgnoreCase(other.buildIdentifier); + } return Integer.parseInt(thisMatcher.group(2)) - Integer.parseInt(otherMatcher.group(2)); } diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendVersionTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendVersionTest.java index 90a745bc2ac..2e79c4a8961 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendVersionTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendVersionTest.java @@ -3,6 +3,7 @@ import org.junit.Assert; import org.junit.Test; +import static com.helger.commons.mock.CommonsAssert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -77,6 +78,18 @@ public void testIsEqualTo() { fromString.isEqualTo(fromConstructor)); } + @Test // #12041 + public void testSimilarBuildIdentifiers() { + FrontendVersion version = new FrontendVersion("1.1.1-SNAPSHOT"); + FrontendVersion equals = new FrontendVersion("1.1.1-SNAPSHOT"); + + assertTrue("Versions be the same", version.isEqualTo(equals)); + assertFalse("Version should not be older", version.isOlderThan(equals)); + assertEquals("Versions should not have a difference", 0, + version.compareTo(equals)); + assertFalse("Version should not be newer", version.isNewerThan(equals)); + } + @Test(expected = NumberFormatException.class) public void faultyStringVersion_throwsException() { new FrontendVersion("12.0b.1");