< prev index next >

src/java.base/share/classes/java/lang/Runtime.java

Print this page

        

@@ -1097,21 +1097,28 @@
 
             Optional<String> optional = Optional.ofNullable(
                     m.group(VersionPattern.OPT_GROUP));
 
             // empty '+'
-            if ((m.group(VersionPattern.PLUS_GROUP) != null)
-                    && !build.isPresent()) {
+            if (!build.isPresent()) {
+                if (m.group(VersionPattern.PLUS_GROUP) != null) {
                 if (optional.isPresent()) {
                     if (pre.isPresent())
                         throw new IllegalArgumentException("'+' found with"
                             + " pre-release and optional components:'" + s
                             + "'");
                 } else {
                     throw new IllegalArgumentException("'+' found with neither"
                         + " build or optional components: '" + s + "'");
                 }
+                } else {
+                    if (optional.isPresent() && !pre.isPresent()) {
+                        throw new IllegalArgumentException("optional component"
+                            + " must be preceeded by a pre-release component"
+                            + " or '+': '" + s + "'");
+                    }
+                }
             }
             return new Version(List.of(version), pre, build, optional);
         }
 
         private static boolean isSimpleNumber(String s) {
< prev index next >