This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/main by this push:
     new c40f1c8f Parse suffixed version without error
c40f1c8f is described below

commit c40f1c8f568c1edcb160e99b36be7a77b62e3f10
Author: Rostislav Svoboda <[email protected]>
AuthorDate: Thu Nov 27 18:19:17 2025 +0100

    Parse suffixed version without error
    
    Signed-off-by: Rostislav Svoboda <[email protected]>
---
 .../opennlp-runtime/src/main/java/opennlp/tools/util/Version.java | 8 +++++---
 opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java   | 8 ++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git 
a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/Version.java 
b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/Version.java
index 64438175..7118e470 100644
--- a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/Version.java
+++ b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/Version.java
@@ -156,13 +156,15 @@ public class Version {
       throw new NumberFormatException("Invalid version format '" + version + 
"', expected two dots!");
     }
 
+    int indexThirdDot = version.indexOf('.', indexSecondDot + 1);
     int indexFirstDash = version.indexOf('-');
 
     int versionEnd;
-    if (indexFirstDash == -1) {
+    if (indexFirstDash == -1 && indexThirdDot == -1) {
       versionEnd = version.length();
-    }
-    else {
+    } else if (indexThirdDot != -1) {
+      versionEnd = indexThirdDot;
+    } else {
       versionEnd = indexFirstDash;
     }
 
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java 
b/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java
index 8921a932..a9b35fda 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java
@@ -36,6 +36,14 @@ public class VersionTest {
         Version.parse("1.5.2"));
   }
 
+  @Test
+  void testParseSuffixedVersion() {
+    Assertions.assertEquals(new Version(1, 5, 4, false),
+        Version.parse("1.5.4.foobar-007"));
+    Assertions.assertEquals(new Version(1, 5, 4, false),
+        Version.parse("1.5.4.foobar"));
+  }
+
   @Test
   void testParseSnapshot() {
     Assertions.assertEquals(new Version(1, 5, 2, true),

Reply via email to