8217405: rmic should reject class files with preview features enabled
authorsmarks
Thu, 11 Apr 2019 12:06:58 -0700
changeset 54518 50b34791a1d2
parent 54517 c201ca660afd
child 54519 a2795025f417
8217405: rmic should reject class files with preview features enabled Reviewed-by: lancea, alanb
src/jdk.rmic/share/classes/sun/tools/java/BinaryClass.java
src/jdk.rmic/share/classes/sun/tools/java/RuntimeConstants.java
src/jdk.rmic/share/classes/sun/tools/javac/resources/javac.properties
--- a/src/jdk.rmic/share/classes/sun/tools/java/BinaryClass.java	Thu Apr 11 14:14:30 2019 -0400
+++ b/src/jdk.rmic/share/classes/sun/tools/java/BinaryClass.java	Thu Apr 11 12:06:58 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -122,6 +122,13 @@
                            sun.tools.javac.Main.getText(
                                "javac.err.version.too.old",
                                String.valueOf(version)));
+        } else if ((version >= JAVA_MIN_PREVIEW_MAJOR_VERSION)
+                     && (minor_version == JAVA_PREVIEW_MINOR_VERSION)) {
+            // reject all class files that have preview features enabled
+            throw new ClassFormatError(
+                           sun.tools.javac.Main.getText(
+                               "javac.err.version.preview",
+                               version+"."+minor_version));
         } else if ((version > JAVA_MAX_SUPPORTED_VERSION)
                      || (version == JAVA_MAX_SUPPORTED_VERSION
                   && minor_version > JAVA_MAX_SUPPORTED_MINOR_VERSION)) {
--- a/src/jdk.rmic/share/classes/sun/tools/java/RuntimeConstants.java	Thu Apr 11 14:14:30 2019 -0400
+++ b/src/jdk.rmic/share/classes/sun/tools/java/RuntimeConstants.java	Thu Apr 11 12:06:58 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -69,6 +69,8 @@
     int JAVA_MIN_SUPPORTED_VERSION   = 45;
     int JAVA_MAX_SUPPORTED_VERSION   = 57;
     int JAVA_MAX_SUPPORTED_MINOR_VERSION = 0;
+    int JAVA_MIN_PREVIEW_MAJOR_VERSION = 55; // preview intro'd in JDK 11
+    int JAVA_PREVIEW_MINOR_VERSION   = 0xffff;
 
     /* Generate class file version for 1.1  by default */
     int JAVA_DEFAULT_VERSION         = 45;
--- a/src/jdk.rmic/share/classes/sun/tools/javac/resources/javac.properties	Thu Apr 11 14:14:30 2019 -0400
+++ b/src/jdk.rmic/share/classes/sun/tools/javac/resources/javac.properties	Thu Apr 11 12:06:58 2019 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -579,6 +579,9 @@
 javac.err.version.too.recent=\
 	The major.minor version ''{0}'' is too recent for this tool \
 	to understand.
+javac.err.version.preview=\
+	The major.minor version ''{0}'' indicates the class was compiled with \
+	preview features enabled, which this tool does not support.
 #
 benv.parsed_in=[parsed {0} in {1} ms]
 benv.loaded_in=[loaded {0} in {1} ms]