@@ -46,7 +46,9 @@ public static void main(String[] args) throws Exception {
4646 if (!jdk .equals (v1 )) {
4747 throw new RuntimeException ("Unmatched version: " + jdk + " vs " + v1 );
4848 }
49- VersionInfo jvm = jvmVersionInfo (System .getProperty ("java.vm.version" ));
49+ VersionInfo jvm = System .getProperty ("java.vm.specification.version" ).equals ("17" ) ?
50+ jvm17VersionInfo (System .getProperty ("java.vm.version" ))
51+ : jvmVersionInfo (System .getProperty ("java.vm.version" ));
5052 VersionInfo v2 = new VersionInfo (jvmMajorVersion (),
5153 jvmMinorVersion (),
5254 jvmMicroVersion (),
@@ -136,6 +138,36 @@ private static VersionInfo jdkVersionInfo(String version) throws Exception {
136138 return vi ;
137139 }
138140
141+ private static VersionInfo jvm17VersionInfo (String version ) throws Exception {
142+ // According to jdk-version.m4 in jdk17u
143+ // valid format of the version string is:
144+ // <major>[.<minor>][.<update>][.<patch>[-<version_pre>]+<build>[-<version_opt>]
145+ int major = 0 ;
146+ int minor = 0 ;
147+ int build = 0 ;
148+
149+ String regex = "^(?<major>[0-9]{1,2})" ; // major
150+ regex += "(\\ ." ; // separator
151+ regex += "(?<minor>[0-9]{1,3})" ; // minor
152+ regex += ")?" ; // minor '0' might be stripped
153+ regex += "(\\ .[0-9]{1,3})?(\\ .[0-9]{1,3})?" ; // (not important) update, patch
154+ regex += "(\\ -[a-zA-Z0-9]+)?" ; // (not important) version_pre
155+ regex += "\\ +(?<build>[0-9]{1,3})" ; // build
156+ regex += "(\\ -[a-zA-Z0-9\\ .\\ -]+)?$" ; // (not important) version_opt
157+
158+ Pattern p = Pattern .compile (regex );
159+ Matcher m = p .matcher (version );
160+ m .matches ();
161+
162+ major = Integer .parseInt (m .group ("major" ));
163+ minor = m .group ("minor" ) == null ? 0 : Integer .parseInt (m .group ("minor" ));
164+ build = Integer .parseInt (m .group ("build" ));
165+
166+ VersionInfo vi = new VersionInfo (major , minor , 0 , 0 , "" , build );
167+ System .out .printf ("jvmVersionInfo: input=%s output=%s\n " , version , vi );
168+ return vi ;
169+ }
170+
139171 private static VersionInfo jvmVersionInfo (String version ) throws Exception {
140172 try {
141173 // valid format of the version string is:
0 commit comments