1 /* 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 6994413 26 * @summary Check the JDK and JVM version returned by sun.misc.Version 27 * matches the versions defined in the system properties 28 * @modules java.base/sun.misc 29 * @compile -XDignore.symbol.file Version.java 30 * @run main Version 31 */ 32 33 import static sun.misc.Version.*; 34 public class Version { 35 36 public static void main(String[] args) throws Exception { 37 VersionInfo jdk = newVersionInfo(System.getProperty("java.runtime.version")); 38 VersionInfo v1 = new VersionInfo(jdkMajorVersion(), 39 jdkMinorVersion(), 40 jdkMicroVersion(), 41 jdkUpdateVersion(), 42 jdkSpecialVersion(), 43 jdkBuildNumber()); 44 System.out.println("JDK version = " + jdk + " " + v1); 45 if (!jdk.equals(v1)) { 46 throw new RuntimeException("Unmatched version: " + jdk + " vs " + v1); 47 } 48 VersionInfo jvm = newVersionInfo(System.getProperty("java.vm.version")); 49 VersionInfo v2 = new VersionInfo(jvmMajorVersion(), 50 jvmMinorVersion(), 51 jvmMicroVersion(), 52 jvmUpdateVersion(), 53 jvmSpecialVersion(), 54 jvmBuildNumber()); 55 System.out.println("JVM version = " + jvm + " " + v2); 56 if (!jvm.equals(v2)) { 57 throw new RuntimeException("Unmatched version: " + jvm + " vs " + v2); 58 } 59 } 60 61 static class VersionInfo { 62 final int major; 63 final int minor; 64 final int micro; 65 final int update; 66 final String special; 67 final int build; 68 VersionInfo(int major, int minor, int micro, 69 int update, String special, int build) { 70 this.major = major; 71 this.minor = minor; | 1 /* 2 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 6994413 26 * @summary Check the JDK and JVM version returned by sun.misc.Version 27 * matches the versions defined in the system properties 28 * @modules java.base/sun.misc 29 * @compile -XDignore.symbol.file Version.java 30 * @run main Version 31 */ 32 33 import static sun.misc.Version.*; 34 public class Version { 35 36 public static void main(String[] args) throws Exception { 37 VersionInfo jdk = newVersionInfo(System.getProperty("java.runtime.version")); 38 VersionInfo v1 = new VersionInfo(jdkMajorVersion(), 39 jdkMinorVersion(), 40 jdkSecurityVersion(), 41 jdkUpdateVersion(), 42 jdkSpecialVersion(), 43 jdkBuildNumber()); 44 System.out.println("JDK version = " + jdk + " " + v1); 45 if (!jdk.equals(v1)) { 46 throw new RuntimeException("Unmatched version: " + jdk + " vs " + v1); 47 } 48 VersionInfo jvm = newVersionInfo(System.getProperty("java.vm.version")); 49 VersionInfo v2 = new VersionInfo(jvmMajorVersion(), 50 jvmMinorVersion(), 51 jvmSecurityVersion(), 52 jvmUpdateVersion(), 53 jvmSpecialVersion(), 54 jvmBuildNumber()); 55 System.out.println("JVM version = " + jvm + " " + v2); 56 if (!jvm.equals(v2)) { 57 throw new RuntimeException("Unmatched version: " + jvm + " vs " + v2); 58 } 59 } 60 61 static class VersionInfo { 62 final int major; 63 final int minor; 64 final int micro; 65 final int update; 66 final String special; 67 final int build; 68 VersionInfo(int major, int minor, int micro, 69 int update, String special, int build) { 70 this.major = major; 71 this.minor = minor; |