changeset 60469:9644aa7f0b72 amber-demo-II

Automatic merge with sealed-types
author mcimadamore
date Fri, 03 Apr 2020 14:26:10 +0000
parents 959d18c21204 6d425512517a
children aa378a711d0d
files src/hotspot/share/classfile/classFileParser.cpp test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java
diffstat 3 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Thu Apr 02 20:06:05 2020 +0000
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Fri Apr 03 14:26:10 2020 +0000
@@ -3214,6 +3214,9 @@
     cfs->guarantee_more(2, CHECK_0);  // length
     length = cfs->get_u2_fast();
   }
+  if (length < 1) {
+    classfile_parse_error("PermittedSubtypes attribute is empty in class file %s", CHECK_0);
+  }
   const int size = length;
   Array<u2>* const permitted_subtypes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
   _permitted_subtypes = permitted_subtypes;
@@ -3776,8 +3779,8 @@
             if (tag == vmSymbols::tag_permitted_subtypes()) {
               if (supports_sealed_types()) {
                 // Check for PermittedSubtypes tag
-                // Classes with empty PermittedSubtype attributes are marked ACC_FINAL.
-                if (_access_flags.is_final() && attribute_length > 2) {
+                // Classes marked ACC_FINAL cannot have a PermittedSubtype attribute.
+                if (_access_flags.is_final()) {
                   classfile_parse_error("PermittedSubtypes attribute in final class file %s", CHECK);
                 }
                 if (parsed_permitted_subtypes_attribute) {
--- a/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod	Thu Apr 02 20:06:05 2020 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod	Fri Apr 03 14:26:10 2020 +0000
@@ -102,7 +102,7 @@
 
 
 // This class contains an empty PermittedSubtypes attribute.  Test that
-// this does not cause an exception to get thrown.
+// this causes an exception to get thrown.
 class noSubtypes {
   0xCAFEBABE;
   65535; // minor version
@@ -124,7 +124,7 @@
     Utf8 "PermittedSubtypes"; // #13     at 0x81
   } // Constant Pool
 
-  0x0030; // access [ ACC_SUPER ACC_FINAL ]
+  0x0020; // access [ ACC_SUPER ]
   #7;// this_cpx
   #2;// super_cpx
 
@@ -327,7 +327,7 @@
 } // end class badPermittedAttr
 
 
-// This class has a non-empty PermittedSubtypes attribute and is marked Final.
+// This class has a PermittedSubtypes attribute and is marked Final.
 // Loading this class should throw a ClassFormatError exception.
 //
 // sealed class sealedButFinal permits iDontExist, I/Dont/Exist/Either { }
--- a/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java	Thu Apr 02 20:06:05 2020 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java	Fri Apr 03 14:26:10 2020 +0000
@@ -111,8 +111,8 @@
         // Test class with PermittedSubtypes attribute but old class file version.
         testSealedInfo(oldClassFile.class, new String[] { });
 
-        // Test class with empty PermittedSubtypes attribute.
-        testSealedInfo(noSubtypes.class, new String[] { });
+        // Test class with an empty PermittedSubtypes attribute.
+        testBadSealedType("noSubtypes", "PermittedSubtypes attribute is empty");
 
         // Test returning names of non-existing classes.
         testSealedInfo(noLoadSubtypes.class, new String[]{"LiDontExist;", "LI/Dont/Exist/Either;"});
@@ -122,8 +122,8 @@
         testBadSealedType("badPermittedAttr",
                           "Permitted subtype class_info_index 15 has bad constant type");
 
-        // Test that loading a sealed final class with a non-empty PermittedSubtypes
+        // Test that loading a sealed final class with a PermittedSubtypes
         // attribute causes a ClassFormatError.
-        testBadSealedType("sealedButFinal", "PermittedSubtypes attribute in final class file");
+        testBadSealedType("sealedButFinal", "PermittedSubtypes attribute in final class");
     }
 }