changeset 12685:fc60138effe1

8176147: JVM should throw CFE for duplicate Signature attributes Summary: Add the needed checks to ClasFileParser for duplicate Signature attributes. Reviewed-by: dholmes, gtriantafill
author hseigel
date Wed, 08 Mar 2017 09:04:21 -0500
parents 6fb85042b428
children ee79788e8427 55e3f1f3d0a7
files src/share/vm/classfile/classFileParser.cpp test/runtime/duplAttributes/DupSignatureAttrs.jcod test/runtime/duplAttributes/TestDupSignatureAttr.java
diffstat 3 files changed, 691 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileParser.cpp	Tue Mar 07 09:32:49 2017 -0800
+++ b/src/share/vm/classfile/classFileParser.cpp	Wed Mar 08 09:04:21 2017 -0500
@@ -1266,6 +1266,10 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (attribute_name == vmSymbols::tag_signature()) {
+        if (generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes for field in class file %s", CHECK);
+        }
         if (attribute_length != 2) {
           classfile_parse_error(
             "Wrong size %u for field's Signature attribute in class file %s",
@@ -2587,6 +2591,11 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (method_attribute_name == vmSymbols::tag_signature()) {
+        if (generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes for method in class file %s",
+            CHECK_NULL);
+        }
         if (method_attribute_length != 2) {
           classfile_parse_error(
             "Invalid Signature attribute length %u in class file %s",
@@ -3306,6 +3315,10 @@
       }
     } else if (_major_version >= JAVA_1_5_VERSION) {
       if (tag == vmSymbols::tag_signature()) {
+        if (_generic_signature_index != 0) {
+          classfile_parse_error(
+            "Multiple Signature attributes in class file %s", CHECK);
+        }
         if (attribute_length != 2) {
           classfile_parse_error(
             "Wrong Signature attribute length %u in class file %s",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/duplAttributes/DupSignatureAttrs.jcod	Wed Mar 08 09:04:21 2017 -0500
@@ -0,0 +1,615 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+
+// Class containing duplicate Signature attributes.  Loading it should cause a
+// ClassFormatError exception.
+class DupClassSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [33] { // Constant Pool
+    ; // first element is empty
+    Method #6 #17; // #1     at 0x0A
+    Field #18 #19; // #2     at 0x0F
+    String #20; // #3     at 0x14
+    Method #21 #22; // #4     at 0x17
+    class #23; // #5     at 0x1C
+    class #24; // #6     at 0x1F
+    Utf8 "<init>"; // #7     at 0x22
+    Utf8 "()V"; // #8     at 0x2B
+    Utf8 "Code"; // #9     at 0x31
+    Utf8 "LineNumberTable"; // #10     at 0x38
+    Utf8 "main"; // #11     at 0x4A
+    Utf8 "([Ljava/lang/String;)V"; // #12     at 0x51
+    Utf8 "Exceptions"; // #13     at 0x6A
+    class #25; // #14     at 0x77
+    Utf8 "SourceFile"; // #15     at 0x7A
+    Utf8 "DupClassSigAttrs.java"; // #16     at 0x87
+    NameAndType #7 #8; // #17     at 0x9F
+    class #26; // #18     at 0xA4
+    NameAndType #27 #28; // #19     at 0xA7
+    Utf8 "hi"; // #20     at 0xAC
+    class #29; // #21     at 0xB1
+    NameAndType #30 #31; // #22     at 0xB4
+    Utf8 "DupClassSigAttrs"; // #23     at 0xB9
+    Utf8 "java/lang/Object"; // #24     at 0xCC
+    Utf8 "java/lang/Throwable"; // #25     at 0xDF
+    Utf8 "java/lang/System"; // #26     at 0xF5
+    Utf8 "out"; // #27     at 0x0108
+    Utf8 "Ljava/io/PrintStream;"; // #28     at 0x010E
+    Utf8 "java/io/PrintStream"; // #29     at 0x0126
+    Utf8 "println"; // #30     at 0x013C
+    Utf8 "(Ljava/lang/String;)V"; // #31     at 0x0146
+    Utf8 "Signature"; // #32     at 0x015E
+  } // Constant Pool
+
+  0x0021; // access
+  #5;// this_cpx
+  #6;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [2] { // methods
+    { // Member at 0x0176
+      0x0001; // access
+      #7; // name_cpx
+      #8; // sig_cpx
+      [1] { // Attributes
+        Attr(#9, 29) { // Code at 0x017E
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 6) { // LineNumberTable at 0x0195
+              [1] { // LineNumberTable
+                0  1; //  at 0x01A1
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x01A1
+      0x0009; // access
+      #11; // name_cpx
+      #12; // sig_cpx
+      [2] { // Attributes
+        Attr(#9, 37) { // Code at 0x01A9
+          2; // max_stack
+          1; // max_locals
+          Bytes[9]{
+            0xB200021203B60004;
+            0xB1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 10) { // LineNumberTable at 0x01C4
+              [2] { // LineNumberTable
+                0  4; //  at 0x01D0
+                8  5; //  at 0x01D4
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#13, 4) { // Exceptions at 0x01D4
+          [1] { // Exceptions
+            #14; //  at 0x01DE
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+  } // methods
+
+  [3] { // Attributes
+    Attr(#15, 2) { // SourceFile at 0x01E0
+      #16;
+    } // end SourceFile
+    ;
+    Attr(#32, 2) { // Signature at 0x01E8
+      #16;
+    } // end Signature
+    ;
+    Attr(#32, 2) { // *** Duplicate *** Signature at 0x01F0
+      #16;
+    } // end Signature
+  } // Attributes
+} // end class DupClassSigAttrs
+
+
+// Class containing a method with duplicate Signature attributes.  Loading it
+// should cause a ClassFormatError exception.
+class DupMthSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [33] { // Constant Pool
+    ; // first element is empty
+    Method #6 #17; // #1     at 0x0A
+    Field #18 #19; // #2     at 0x0F
+    String #20; // #3     at 0x14
+    Method #21 #22; // #4     at 0x17
+    class #23; // #5     at 0x1C
+    class #24; // #6     at 0x1F
+    Utf8 "<init>"; // #7     at 0x22
+    Utf8 "()V"; // #8     at 0x2B
+    Utf8 "Code"; // #9     at 0x31
+    Utf8 "LineNumberTable"; // #10     at 0x38
+    Utf8 "main"; // #11     at 0x4A
+    Utf8 "([Ljava/lang/String;)V"; // #12     at 0x51
+    Utf8 "Exceptions"; // #13     at 0x6A
+    class #25; // #14     at 0x77
+    Utf8 "SourceFile"; // #15     at 0x7A
+    Utf8 "DupMthSigAttrs.java"; // #16     at 0x87
+    NameAndType #7 #8; // #17     at 0x9D
+    class #26; // #18     at 0xA2
+    NameAndType #27 #28; // #19     at 0xA5
+    Utf8 "hi"; // #20     at 0xAA
+    class #29; // #21     at 0xAF
+    NameAndType #30 #31; // #22     at 0xB2
+    Utf8 "DupMthSigAttrs"; // #23     at 0xB7
+    Utf8 "java/lang/Object"; // #24     at 0xC8
+    Utf8 "java/lang/Throwable"; // #25     at 0xDB
+    Utf8 "java/lang/System"; // #26     at 0xF1
+    Utf8 "out"; // #27     at 0x0104
+    Utf8 "Ljava/io/PrintStream;"; // #28     at 0x010A
+    Utf8 "java/io/PrintStream"; // #29     at 0x0122
+    Utf8 "println"; // #30     at 0x0138
+    Utf8 "(Ljava/lang/String;)V"; // #31     at 0x0142
+    Utf8 "Signature"; // #32     at 0x015A
+  } // Constant Pool
+
+  0x0021; // access
+  #5;// this_cpx
+  #6;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [2] { // methods
+    { // Member at 0x0172
+      0x0001; // access
+      #7; // name_cpx
+      #8; // sig_cpx
+      [1] { // Attributes
+        Attr(#9, 29) { // Code at 0x017A
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 6) { // LineNumberTable at 0x0191
+              [1] { // LineNumberTable
+                0  1; //  at 0x019D
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x019D
+      0x0009; // access
+      #11; // name_cpx
+      #12; // sig_cpx
+      [4] { // Attributes
+        Attr(#9, 37) { // Code at 0x01A5
+          2; // max_stack
+          1; // max_locals
+          Bytes[9]{
+            0xB200021203B60004;
+            0xB1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 10) { // LineNumberTable at 0x01C0
+              [2] { // LineNumberTable
+                0  4; //  at 0x01CC
+                8  5; //  at 0x01D0
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#32, 2) { // Signature at 0x01D0
+          #16;
+        } // end Signature
+        ;
+        Attr(#13, 4) { // Exceptions at 0x01D8
+          [1] { // Exceptions
+            #14; //  at 0x01E2
+          }
+        } // end Exceptions
+        ;
+        Attr(#32, 2) { // *** Duplicate *** Signature at 0x01E2
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#15, 2) { // SourceFile at 0x01EC
+      #16;
+    } // end SourceFile
+  } // Attributes
+} // end class DupMthSigAttrs
+
+
+// Class containing a field with duplicate Signature attributes.  Loading it
+// should cause a ClassFormatError exception.
+class DupFldSigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [42] { // Constant Pool
+    ; // first element is empty
+    Method #9 #23; // #1     at 0x0A
+    Field #24 #25; // #2     at 0x0F
+    Field #8 #26; // #3     at 0x14
+    Method #27 #28; // #4     at 0x19
+    class #29; // #5     at 0x1E
+    String #30; // #6     at 0x21
+    Method #5 #31; // #7     at 0x24
+    class #32; // #8     at 0x29
+    class #33; // #9     at 0x2C
+    Utf8 "str"; // #10     at 0x2F
+    Utf8 "Ljava/lang/String;"; // #11     at 0x35
+    Utf8 "<init>"; // #12     at 0x4A
+    Utf8 "()V"; // #13     at 0x53
+    Utf8 "Code"; // #14     at 0x59
+    Utf8 "LineNumberTable"; // #15     at 0x60
+    Utf8 "main"; // #16     at 0x72
+    Utf8 "([Ljava/lang/String;)V"; // #17     at 0x79
+    Utf8 "Exceptions"; // #18     at 0x92
+    class #34; // #19     at 0x9F
+    Utf8 "<clinit>"; // #20     at 0xA2
+    Utf8 "SourceFile"; // #21     at 0xAD
+    Utf8 "DupFldSigAttrs.java"; // #22     at 0xBA
+    NameAndType #12 #13; // #23     at 0xD0
+    class #35; // #24     at 0xD5
+    NameAndType #36 #37; // #25     at 0xD8
+    NameAndType #10 #11; // #26     at 0xDD
+    class #38; // #27     at 0xE2
+    NameAndType #39 #40; // #28     at 0xE5
+    Utf8 "java/lang/String"; // #29     at 0xEA
+    Utf8 "Hi"; // #30     at 0xFD
+    NameAndType #12 #40; // #31     at 0x0102
+    Utf8 "DupFldSigAttrs"; // #32     at 0x0107
+    Utf8 "java/lang/Object"; // #33     at 0x0118
+    Utf8 "java/lang/Throwable"; // #34     at 0x012B
+    Utf8 "java/lang/System"; // #35     at 0x0141
+    Utf8 "out"; // #36     at 0x0154
+    Utf8 "Ljava/io/PrintStream;"; // #37     at 0x015A
+    Utf8 "java/io/PrintStream"; // #38     at 0x0172
+    Utf8 "println"; // #39     at 0x0188
+    Utf8 "(Ljava/lang/String;)V"; // #40     at 0x0192
+    Utf8 "Signature"; // #41     at 0x01AA
+  } // Constant Pool
+
+  0x0021; // access
+  #8;// this_cpx
+  #9;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [1] { // fields
+    { // Member at 0x01C0
+      0x0008; // access
+      #10; // name_cpx
+      #11; // sig_cpx
+      [2] { // Attributes
+        Attr(#41, 2) { // Signature at 0x01C8
+          #16;
+        } // end Signature
+        ;
+        Attr(#41, 2) { // *** Duplicate *** Signature at 0x01D0
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // fields
+
+  [3] { // methods
+    { // Member at 0x01DA
+      0x0001; // access
+      #12; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 29) { // Code at 0x01E2
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x01F9
+              [1] { // LineNumberTable
+                0  1; //  at 0x0205
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0205
+      0x0009; // access
+      #16; // name_cpx
+      #17; // sig_cpx
+      [2] { // Attributes
+        Attr(#14, 38) { // Code at 0x020D
+          2; // max_stack
+          1; // max_locals
+          Bytes[10]{
+            0xB20002B20003B600;
+            0x04B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 10) { // LineNumberTable at 0x0229
+              [2] { // LineNumberTable
+                0  6; //  at 0x0235
+                9  7; //  at 0x0239
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#18, 4) { // Exceptions at 0x0239
+          [1] { // Exceptions
+            #19; //  at 0x0243
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0243
+      0x0008; // access
+      #20; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 37) { // Code at 0x024B
+          3; // max_stack
+          0; // max_locals
+          Bytes[13]{
+            0xBB0005591206B700;
+            0x07B30003B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x026A
+              [1] { // LineNumberTable
+                0  3; //  at 0x0276
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#21, 2) { // SourceFile at 0x0278
+      #22;
+    } // end SourceFile
+  } // Attributes
+} // end class DupFldSigAttrs
+
+
+// Class containing a Signature attribute and a field and methods with Signature
+// attributes.  Since neither the class nor any of its fields or methods have
+// duplicate Signature attributes, loading this class should not cause a
+// ClassFormatError exception.
+class OkaySigAttrs {
+  0xCAFEBABE;
+  0; // minor version
+  53; // version
+  [42] { // Constant Pool
+    ; // first element is empty
+    Method #9 #23; // #1     at 0x0A
+    Field #24 #25; // #2     at 0x0F
+    Field #8 #26; // #3     at 0x14
+    Method #27 #28; // #4     at 0x19
+    class #29; // #5     at 0x1E
+    String #30; // #6     at 0x21
+    Method #5 #31; // #7     at 0x24
+    class #32; // #8     at 0x29
+    class #33; // #9     at 0x2C
+    Utf8 "str"; // #10     at 0x2F
+    Utf8 "Ljava/lang/String;"; // #11     at 0x35
+    Utf8 "<init>"; // #12     at 0x4A
+    Utf8 "()V"; // #13     at 0x53
+    Utf8 "Code"; // #14     at 0x59
+    Utf8 "LineNumberTable"; // #15     at 0x60
+    Utf8 "main"; // #16     at 0x72
+    Utf8 "([Ljava/lang/String;)V"; // #17     at 0x79
+    Utf8 "Exceptions"; // #18     at 0x92
+    class #34; // #19     at 0x9F
+    Utf8 "<clinit>"; // #20     at 0xA2
+    Utf8 "SourceFile"; // #21     at 0xAD
+    Utf8 "OkaySigAttrs.java"; // #22     at 0xBA
+    NameAndType #12 #13; // #23     at 0xCE
+    class #35; // #24     at 0xD3
+    NameAndType #36 #37; // #25     at 0xD6
+    NameAndType #10 #11; // #26     at 0xDB
+    class #38; // #27     at 0xE0
+    NameAndType #39 #40; // #28     at 0xE3
+    Utf8 "java/lang/String"; // #29     at 0xE8
+    Utf8 "Hi"; // #30     at 0xFB
+    NameAndType #12 #40; // #31     at 0x0100
+    Utf8 "OkaySigAttrs"; // #32     at 0x0105
+    Utf8 "java/lang/Object"; // #33     at 0x0114
+    Utf8 "java/lang/Throwable"; // #34     at 0x0127
+    Utf8 "java/lang/System"; // #35     at 0x013D
+    Utf8 "out"; // #36     at 0x0150
+    Utf8 "Ljava/io/PrintStream;"; // #37     at 0x0156
+    Utf8 "java/io/PrintStream"; // #38     at 0x016E
+    Utf8 "println"; // #39     at 0x0184
+    Utf8 "(Ljava/lang/String;)V"; // #40     at 0x018E
+    Utf8 "Signature"; // #41     at 0x01A6
+  } // Constant Pool
+
+  0x0021; // access
+  #8;// this_cpx
+  #9;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [1] { // fields
+    { // Member at 0x01BC
+      0x0008; // access
+      #10; // name_cpx
+      #11; // sig_cpx
+      [1] { // Attributes
+        Attr(#41, 2) { // Signature at 0x01C4
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+  } // fields
+
+  [3] { // methods
+    { // Member at 0x01CE
+      0x0001; // access
+      #12; // name_cpx
+      #13; // sig_cpx
+      [2] { // Attributes
+        Attr(#14, 29) { // Code at 0x01D6
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x01ED
+              [1] { // LineNumberTable
+                0  1; //  at 0x01F9
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#41, 2) { // Signature at 0x01F9
+          #16;
+        } // end Signature
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0201
+      0x0009; // access
+      #16; // name_cpx
+      #17; // sig_cpx
+      [3] { // Attributes
+        Attr(#14, 38) { // Code at 0x0209
+          2; // max_stack
+          1; // max_locals
+          Bytes[10]{
+            0xB20002B20003B600;
+            0x04B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 10) { // LineNumberTable at 0x0225
+              [2] { // LineNumberTable
+                0  6; //  at 0x0231
+                9  7; //  at 0x0235
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+        ;
+        Attr(#41, 2) { // Signature at 0x0235
+          #16;
+        } // end Signature
+        ;
+        Attr(#18, 4) { // Exceptions at 0x023D
+          [1] { // Exceptions
+            #19; //  at 0x0247
+          }
+        } // end Exceptions
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x0247
+      0x0008; // access
+      #20; // name_cpx
+      #13; // sig_cpx
+      [1] { // Attributes
+        Attr(#14, 37) { // Code at 0x024F
+          3; // max_stack
+          0; // max_locals
+          Bytes[13]{
+            0xBB0005591206B700;
+            0x07B30003B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#15, 6) { // LineNumberTable at 0x026E
+              [1] { // LineNumberTable
+                0  3; //  at 0x027A
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [2] { // Attributes
+    Attr(#21, 2) { // SourceFile at 0x027C
+      #22;
+    } // end SourceFile
+    ;
+    Attr(#41, 2) { // Signature at 0x0284
+      #16;
+    } // end Signature
+  } // Attributes
+} // end class OkaySigAttrs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/duplAttributes/TestDupSignatureAttr.java	Wed Mar 08 09:04:21 2017 -0500
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017, 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 8176147
+ * @summary Throw ClassFormatError exception for multiple Signature attributes
+ * @compile DupSignatureAttrs.jcod
+ * @run main TestDupSignatureAttr
+ */
+
+public class TestDupSignatureAttr {
+    public static void main(String args[]) throws Throwable {
+
+        System.out.println("Regression test for bug 8176147");
+
+        String[] badClasses = new String[] {
+            "DupClassSigAttrs",
+            "DupMthSigAttrs",
+            "DupFldSigAttrs",
+        };
+        String[] messages = new String[] {
+            "Multiple Signature attributes in class file",
+            "Multiple Signature attributes for method",
+            "Multiple Signature attributes for field",
+        };
+
+        for (int x = 0; x < badClasses.length; x++) {
+            try {
+                Class newClass = Class.forName(badClasses[x]);
+                throw new RuntimeException("Expected ClassFormatError exception not thrown");
+            } catch (java.lang.ClassFormatError e) {
+                if (!e.getMessage().contains(messages[x])) {
+                    throw new RuntimeException("Wrong ClassFormatError exception thrown: " +
+                                               e.getMessage());
+                }
+            }
+        }
+
+        // Multiple Signature attributes but no duplicates.
+        Class newClass = Class.forName("OkaySigAttrs");
+    }
+}