You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by rz...@apache.org on 2025/11/29 19:04:40 UTC

(opennlp) branch opennlp-2.x updated: Parse suffixed version without error

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

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


The following commit(s) were added to refs/heads/opennlp-2.x by this push:
     new 707148a6 Parse suffixed version without error
707148a6 is described below

commit 707148a6413a16fec876993b79b74f3357ea3203
Author: Rostislav Svoboda <ro...@gmail.com>
AuthorDate: Fri Nov 28 09:29:30 2025 +0100

    Parse suffixed version without error
    
    Signed-off-by: Rostislav Svoboda <ro...@gmail.com>
---
 opennlp-tools/src/main/java/opennlp/tools/util/Version.java     | 5 ++++-
 opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Version.java b/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
index 7fd7de0d..06ce68a6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
@@ -156,11 +156,14 @@ 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 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 3133777f..6c0d6d34 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/VersionTest.java
@@ -44,6 +44,14 @@ public class VersionTest {
         Version.parse("1.5.2-SNAPSHOT"));
   }
 
+  @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 testParseProjectVersionWithRarePatchVersion() {
     // A rare extra patch version is present (e.g., 2.5.6.1), which OpenNLP normally doesn't use.