--- old/src/share/vm/classfile/classFileParser.cpp 2014-04-22 09:09:16.468300000 -0400 +++ new/src/share/vm/classfile/classFileParser.cpp 2014-04-22 09:09:14.100281000 -0400 @@ -888,6 +888,7 @@ int runtime_visible_type_annotations_length = 0; u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; + bool runtime_invisible_annotations_exists = false; bool runtime_invisible_type_annotations_exists = false; while (attributes_count--) { cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length @@ -933,6 +934,10 @@ } generic_signature_index = cfs->get_u2(CHECK); } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) { + if (runtime_visible_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleAnnotations attributes for field in class file %s", CHECK); + } runtime_visible_annotations_length = attribute_length; runtime_visible_annotations = cfs->get_u1_buffer(); assert(runtime_visible_annotations != NULL, "null visible annotations"); @@ -941,11 +946,18 @@ parsed_annotations, CHECK); cfs->skip_u1(runtime_visible_annotations_length, CHECK); - } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { - runtime_invisible_annotations_length = attribute_length; - runtime_invisible_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_annotations != NULL, "null invisible annotations"); - cfs->skip_u1(runtime_invisible_annotations_length, CHECK); + } else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { + if (runtime_invisible_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleAnnotations attributes for field in class file %s", CHECK); + } + runtime_invisible_annotations_exists = true; + if (PreserveAllAnnotations) { + runtime_invisible_annotations_length = attribute_length; + runtime_invisible_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_annotations != NULL, "null invisible annotations"); + } + cfs->skip_u1(attribute_length, CHECK); } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { if (runtime_visible_type_annotations != NULL) { classfile_parse_error( @@ -2079,7 +2091,9 @@ int runtime_visible_type_annotations_length = 0; u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; + bool runtime_invisible_annotations_exists = false; bool runtime_invisible_type_annotations_exists = false; + bool runtime_invisible_parameter_annotations_exists = false; u1* annotation_default = NULL; int annotation_default_length = 0; @@ -2308,6 +2322,10 @@ cfs->guarantee_more(2, CHECK_(nullHandle)); // generic_signature_index generic_signature_index = cfs->get_u2_fast(); } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) { + if (runtime_visible_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleAnnotations attributes for method in class file %s", CHECK_(nullHandle)); + } runtime_visible_annotations_length = method_attribute_length; runtime_visible_annotations = cfs->get_u1_buffer(); assert(runtime_visible_annotations != NULL, "null visible annotations"); @@ -2315,22 +2333,45 @@ runtime_visible_annotations_length, &parsed_annotations, CHECK_(nullHandle)); cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); - } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { - runtime_invisible_annotations_length = method_attribute_length; - runtime_invisible_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_annotations != NULL, "null invisible annotations"); - cfs->skip_u1(runtime_invisible_annotations_length, CHECK_(nullHandle)); + } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { + if (runtime_invisible_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleAnnotations attributes for method in class file %s", CHECK_(nullHandle)); + } + runtime_invisible_annotations_exists = true; + if (PreserveAllAnnotations) { + runtime_invisible_annotations_length = method_attribute_length; + runtime_invisible_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_annotations != NULL, "null invisible annotations"); + } + cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) { + if (runtime_visible_parameter_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s", CHECK_(nullHandle)); + } runtime_visible_parameter_annotations_length = method_attribute_length; runtime_visible_parameter_annotations = cfs->get_u1_buffer(); assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations"); cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle)); - } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) { - runtime_invisible_parameter_annotations_length = method_attribute_length; - runtime_invisible_parameter_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations"); - cfs->skip_u1(runtime_invisible_parameter_annotations_length, CHECK_(nullHandle)); + } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) { + if (runtime_invisible_parameter_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleParameterAnnotations attributes for method in class file %s", CHECK_(nullHandle)); + } + runtime_invisible_parameter_annotations_exists = true; + if (PreserveAllAnnotations) { + runtime_invisible_parameter_annotations_length = method_attribute_length; + runtime_invisible_parameter_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations"); + } + cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); } else if (method_attribute_name == vmSymbols::tag_annotation_default()) { + if (annotation_default != NULL) { + classfile_parse_error( + "Multiple AnnotationDefault attributes for method in class file %s", + CHECK_(nullHandle)); + } annotation_default_length = method_attribute_length; annotation_default = cfs->get_u1_buffer(); assert(annotation_default != NULL, "null annotation default"); @@ -2859,6 +2900,8 @@ u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; bool runtime_invisible_type_annotations_exists = false; + bool runtime_invisible_annotations_exists = false; + bool parsed_source_debug_ext_annotations_exist = false; u1* inner_classes_attribute_start = NULL; u4 inner_classes_attribute_length = 0; u2 enclosing_method_class_index = 0; @@ -2886,6 +2929,11 @@ parse_classfile_sourcefile_attribute(CHECK); } else if (tag == vmSymbols::tag_source_debug_extension()) { // Check for SourceDebugExtension tag + if (parsed_source_debug_ext_annotations_exist) { + classfile_parse_error( + "Multiple SourceDebugExtension attributes in class file %s", CHECK); + } + parsed_source_debug_ext_annotations_exist = true; parse_classfile_source_debug_extension_attribute((int)attribute_length, CHECK); } else if (tag == vmSymbols::tag_inner_classes()) { // Check for InnerClasses tag @@ -2922,6 +2970,10 @@ } parse_classfile_signature_attribute(CHECK); } else if (tag == vmSymbols::tag_runtime_visible_annotations()) { + if (runtime_visible_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleAnnotations attributes in class file %s", CHECK); + } runtime_visible_annotations_length = attribute_length; runtime_visible_annotations = cfs->get_u1_buffer(); assert(runtime_visible_annotations != NULL, "null visible annotations"); @@ -2930,11 +2982,18 @@ parsed_annotations, CHECK); cfs->skip_u1(runtime_visible_annotations_length, CHECK); - } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) { - runtime_invisible_annotations_length = attribute_length; - runtime_invisible_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_annotations != NULL, "null invisible annotations"); - cfs->skip_u1(runtime_invisible_annotations_length, CHECK); + } else if (tag == vmSymbols::tag_runtime_invisible_annotations()) { + if (runtime_invisible_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleAnnotations attributes in class file %s", CHECK); + } + runtime_invisible_annotations_exists = true; + if (PreserveAllAnnotations) { + runtime_invisible_annotations_length = attribute_length; + runtime_invisible_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_annotations != NULL, "null invisible annotations"); + } + cfs->skip_u1(attribute_length, CHECK); } else if (tag == vmSymbols::tag_enclosing_method()) { if (parsed_enclosingmethod_attribute) { classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK); --- /dev/null 2014-02-27 06:48:16.520499775 -0500 +++ new/test/runtime/duplAttributes/DuplAttributes.jcod 2014-04-22 09:09:42.367420000 -0400 @@ -0,0 +1,1310 @@ +/* + * Copyright (c) 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * This file contains ten different sub-tests. Each sub-test consists of a + * class with a different case of an invalid duplicate attribute. The main + * test runs each of these tests individually. If any of them fail then the + * whole test fails. + */ + + + +/* + * This test contains a class with invalid duplicate AnnotationDefault attributes. + */ +class AnnotationDefaultDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "AnnotationDefault"; // #9 + Utf8 "LAnnotationDefaultI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "AnnotationDefaultDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "AnnotationDefaultDupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + ; + + Attr(#9) { // AnnotationDefault + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end AnnotationDefault + // wrong: + ; + Attr(#9) { // AnnotationDefault + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end AnnotationDefault + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // AnnotationDefault + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end AnnotationDefault + } // Attributes + +} // end class + + + +/* + * This test contains a class with invalid duplicate RuntimeInvisibleAnnotations + * attributes. + */ +class ClassInvisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "RuntimeInvisibleAnnotations"; // #9 + Utf8 "LClassInvisAnnotsI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "ClassInvisAnnotsDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "ClassInvisAnnotsDupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations +// wrong: + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations +// end wrong + } // Attributes + +} // end class + + + +/* + * This test contains a class with invalid duplicate RuntimeVisibleAnnotations + * attributes. + */ +class ClassVisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "RuntimeVisibleAnnotations"; // #9 + Utf8 "LClassVisAnnotsI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "ClassVisAnnotsDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "ClassVisAnnotsDupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations +// wrong: + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations +// end wrong + } // Attributes + +} // end class + + + +/* + * This test contains a field with invalid duplicate RuntimeInvisibleAnnotations + * attributes. + */ +class FieldInvisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #4 #16; // #1 + Method #17 #18; // #2 + class #19; // #3 + class #20; // #4 + Utf8 "fld"; // #5 + Utf8 "Ljava/util/ArrayList;"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/util/ArrayList;"; // #8 + Utf8 "RuntimeInvisibleAnnotations"; // #9 + Utf8 "LFieldInvisAnnotsI;"; // #10 + Utf8 ""; // #11 + Utf8 "()V"; // #12 + Utf8 "Code"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #11 #12; // #16 + class #21; // #17 + NameAndType #14 #15; // #18 + Utf8 "FieldInvisAnnotsDup"; // #19 + Utf8 "java/lang/Object"; // #20 + Utf8 "FieldInvisAnnotsDupChecker"; // #21 + } // Constant Pool + + 0x0021; // access + #3;// this_cpx + #4;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + { // Member + 0x0001; // access + #5; // name_cpx + #6; // sig_cpx + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations + // wrong: + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations + // end wrong + } // Attributes + } // Member + } // fields + + [] { // methods + { // Member + 0x0001; // access + #11; // name_cpx + #12; // sig_cpx + [] { // Attributes + Attr(#13) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#13) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80002AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + } // Attributes +} // end class + + + +/* + * This test contains a field with invalid duplicate RuntimeVisibleAnnotations + * attributes. + */ +class FieldVisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #4 #16; // #1 + Method #17 #18; // #2 + class #19; // #3 + class #20; // #4 + Utf8 "fld"; // #5 + Utf8 "Ljava/util/ArrayList;"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/util/ArrayList;"; // #8 + Utf8 "RuntimeVisibleAnnotations"; // #9 + Utf8 "LFieldVisAnnotsI;"; // #10 + Utf8 ""; // #11 + Utf8 "()V"; // #12 + Utf8 "Code"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #11 #12; // #16 + class #21; // #17 + NameAndType #14 #15; // #18 + Utf8 "FieldVisAnnotsDup"; // #19 + Utf8 "java/lang/Object"; // #20 + Utf8 "FieldVisAnnotsDupChecker"; // #21 + } // Constant Pool + + 0x0021; // access + #3;// this_cpx + #4;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + { // Member + 0x0001; // access + #5; // name_cpx + #6; // sig_cpx + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations + // wrong: + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations + // end wrong + } // Attributes + } // Member + } // fields + + [] { // methods + { // Member + 0x0001; // access + #11; // name_cpx + #12; // sig_cpx + [] { // Attributes + Attr(#13) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#13) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80002AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + } // Attributes +} // end class + + + +/* + * This test contains a method with invalid duplicate RuntimeInvisibleAnnotations + * attributes. + */ +class MethInvisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "RuntimeInvisibleAnnotations"; // #9 + Utf8 "LMethInvisAnnotsI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "MethInvisAnnotsDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "MethInvisAnnotsDupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + ; + + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations + // wrong: + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeInvisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeInvisibleAnnotations + } // Attributes + +} // end class + + + +/* + * This test contains a method with invalid duplicate + * RuntimeInvisibleParameterAnnotations attributes. + */ +class MethInvisParamAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #4 #16; // #1 + Method #17 #18; // #2 + class #19; // #3 + class #20; // #4 + Utf8 ""; // #5 + Utf8 "()V"; // #6 + Utf8 "Code"; // #7 + Utf8 "m"; // #8 + Utf8 "()I"; // #9 + Utf8 "Signature"; // #10 + Utf8 "()I"; // #11 + Utf8 "RuntimeInvisibleParameterAnnotations"; // #12 + Utf8 "LMethInvisParamAnnotsI;"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #5 #6; // #16 + class #21; // #17 + NameAndType #14 #15; // #18 + Utf8 "MethInvisParamAnnotsDup"; // #19 + Utf8 "java/lang/Object"; // #20 + Utf8 "MethInvisParamAnnotsDupChecker"; // #21 + } // Constant Pool + + 0x0021; // access + #3;// this_cpx + #4;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #5; // name_cpx + #6; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0001; // access + #8; // name_cpx + #9; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x03AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + ; + Attr(#10) { // Signature + #11; + } // end Signature + ; + Attr(#12) { // RuntimeInvisibleParameterAnnotations + 0x0001010000000D00; + 0x00; + } // end RuntimeInvisibleParameterAnnotations +// wrong: + ; + Attr(#12) { // RuntimeInvisibleParameterAnnotations + 0x0001010000000D00; + 0x00; + } // end RuntimeInvisibleParameterAnnotations +// end wrong + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80002AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + } // Attributes +} // end class + + + +/* + * This test contains a method with invalid duplicate RuntimeVisibleAnnotations + * attributes. + */ +class MethVisAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "RuntimeVisibleAnnotations"; // #9 + Utf8 "LMethodVisAnnotsDupI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "MethVisAnnotsDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "MethVisAnnotsDupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + ; + + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations + // wrong: + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // RuntimeVisibleAnnotations + [] { // type annotations + { // type annotation + 0x00; // target_type + 0x00; // type_parameter_index + []b { // type_path + } + + #10; // type_index + [] { // element_value_pairs + } // element_value_pairs + } // type annotation + } // type annotations + } // end RuntimeVisibleAnnotations + } // Attributes + +} // end class + + + +/* + * This test contains a method with invalid duplicate + * RuntimeVisibleParameterAnnotations attributes. + */ +class MethVisParamAnnotsDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #4 #16; // #1 + Method #17 #18; // #2 + class #19; // #3 + class #20; // #4 + Utf8 ""; // #5 + Utf8 "()V"; // #6 + Utf8 "Code"; // #7 + Utf8 "m"; // #8 + Utf8 "()I"; // #9 + Utf8 "Signature"; // #10 + Utf8 "()I"; // #11 + Utf8 "RuntimeVisibleParameterAnnotations"; // #12 + Utf8 "LMethVisParamAnnotsI;"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #5 #6; // #16 + class #21; // #17 + NameAndType #14 #15; // #18 + Utf8 "MethVisParamAnnotsDup"; // #19 + Utf8 "java/lang/Object"; // #20 + Utf8 "MethVisParamAnnotsDupChecker"; // #21 + } // Constant Pool + + 0x0021; // access + #3;// this_cpx + #4;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #5; // name_cpx + #6; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0001; // access + #8; // name_cpx + #9; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x03AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + ; + Attr(#10) { // Signature + #11; + } // end Signature + ; + Attr(#12) { // RuntimeVisibleParameterAnnotations + 0x0001010000000D00; + 0x00; + } // end RuntimeVisibleParameterAnnotations +// wrong: + ; + Attr(#12) { // RuntimeVisibleParameterAnnotations + 0x0001010000000D00; + 0x00; + } // end RuntimeVisibleParameterAnnotations +// end wrong + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#7) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80002AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + } // Attributes +} // end class + + + +/* + * This test contains a method with invalid duplicate SourceDebugExtension + * attributes. + */ +class SrcDbgExtDup { + 0xCAFEBABE; + 0; // minor version + 52; // version + [] { // Constant Pool + ; // first element is empty + Method #3 #11; // #1 + class #12; // #2 + class #13; // #3 + Utf8 ""; // #4 + Utf8 "()V"; // #5 + Utf8 "Code"; // #6 + Utf8 "Signature"; // #7 + Utf8 "Ljava/lang/Object;"; // #8 + Utf8 "SourceDebugExtension"; // #9 + Utf8 "LSrcDbgExtDupI;"; // #10 + NameAndType #4 #5; // #11 + Utf8 "SrcDbgExtDup"; // #12 + Utf8 "java/lang/Object"; // #13 + Utf8 "run"; // #14 + Utf8 "([Ljava/lang/String;Ljava/io/PrintStream;)I"; // #15 + NameAndType #14 #15; // #16 + class #19; // #17 + Method #17 #16; // #18 + Utf8 "SrcDbgExt_dupChecker"; // #19 + } // Constant Pool + + 0x0021; // access + #2;// this_cpx + #3;// super_cpx + + [] { // Interfaces + } // Interfaces + + [] { // fields + } // fields + + [] { // methods + { // Member + 0x0001; // access + #4; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 1; // max_stack + 1; // max_locals + Bytes[]{ + 0x2AB70001B1; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member + 0x0009; // access + #14; // name_cpx + #15; // sig_cpx + [] { // Attributes + Attr(#6) { // Code + 2; // max_stack + 2; // max_locals + Bytes[]{ + 0x2A2BB80012AC; + }; + [] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + Attr(#7) { // Signature + #8; + } // end Signature + ; + Attr(#9) { // SourceDebugExtension + [] { // debug_extensions + { // type debug_extension + []b { // type_path + } + } // type debug_extension + } // type debug_extensions + } // end SourceDebugExtension +// wrong: + ; + Attr(#9) { // SourceDebugExtension + [] { // debug_extensions + { // type debug_extension + []b { // type_path + } + } // type debug_extension + } // type debug_extensions + } // end SourceDebugExtension +// end wrong + } // Attributes + +} // end class --- /dev/null 2014-02-27 06:48:16.520499775 -0500 +++ new/test/runtime/duplAttributes/DuplAttributesTest.java 2014-04-22 09:09:53.746763000 -0400 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8040292 + * @library /testlibrary + * @summary Throw exceptions when duplicate attributes are detected. + * @run main DuplAttributesTest + */ + +import java.io.File; +import com.oracle.java.testlibrary.*; + +public class DuplAttributesTest { + + static final String testsrc = System.getProperty("test.src"); + + public static void runTest(String test, String result) throws Throwable { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-cp", testsrc + File.separator + "test.jar", test); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("java.lang.ClassFormatError: Multiple " + result); + } + + public static void main(String args[]) throws Throwable { + System.out.println("Regression test for bug 8040292"); + + runTest("ClassInvisAnnotsDup", "RuntimeInvisibleAnnotations"); + runTest("ClassVisAnnotsDup", "RuntimeVisibleAnnotations"); + runTest("SrcDbgExtDup", "SourceDebugExtension"); + + runTest("FieldInvisAnnotsDup", "RuntimeInvisibleAnnotations"); + runTest("FieldVisAnnotsDup", "RuntimeVisibleAnnotations"); + + runTest("AnnotationDefaultDup", "AnnotationDefault"); + runTest("MethInvisAnnotsDup", "RuntimeInvisibleAnnotations"); + runTest("MethVisAnnotsDup", "RuntimeVisibleAnnotations"); + runTest("MethInvisParamAnnotsDup", "RuntimeInvisibleParameterAnnotations"); + runTest("MethVisParamAnnotsDup", "RuntimeVisibleParameterAnnotations"); + } +} +