author | ctornqvi |
Fri, 19 Aug 2016 10:06:30 -0400 | |
changeset 40631 | ed82623d7831 |
parent 33799 | 77ebbd9b0ecc |
child 41705 | 332239c052cc |
permissions | -rw-r--r-- |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
1 |
/* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
4 |
* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
8 |
* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
13 |
* accompanied this code). |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
14 |
* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
18 |
* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
21 |
* questions. |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
22 |
* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
23 |
*/ |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
24 |
|
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
25 |
/* |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
26 |
* @test |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
27 |
* @bug 8130669 |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
28 |
* @summary VM prohibits <clinit> methods with return values |
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
29 |
* @compile nonvoidClinit.jasm |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
30 |
* @compile clinitNonStatic.jasm |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
31 |
* @compile clinitArg.jasm |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
32 |
* @compile clinitArg51.jasm |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
33 |
* @compile badInit.jasm |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
34 |
* @run main/othervm -Xverify:all BadInitMethod |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
35 |
*/ |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
36 |
|
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
37 |
// Test that non-void <clinit>, non-static <clinit>, and non-void |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
38 |
// <init> methods cause ClassFormatException's to be thrown. |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
39 |
public class BadInitMethod { |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
40 |
public static void main(String args[]) throws Throwable { |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
41 |
|
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
42 |
System.out.println("Regression test for bug 8130669"); |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
43 |
try { |
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
44 |
Class newClass = Class.forName("nonvoidClinit"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
45 |
throw new RuntimeException( |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
46 |
"Expected ClassFormatError exception for non-void <clinit> not thrown"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
47 |
} catch (java.lang.ClassFormatError e) { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
48 |
System.out.println("Test BadInitMethod passed for non-void <clinit>"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
49 |
} |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
50 |
|
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
51 |
try { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
52 |
Class newClass = Class.forName("clinitNonStatic"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
53 |
throw new RuntimeException( |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
54 |
"Expected ClassFormatError exception for non-static <clinit> not thrown"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
55 |
} catch (java.lang.ClassFormatError e) { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
56 |
System.out.println("Test BadInitMethod passed for non-static <clinit>"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
57 |
} |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
58 |
|
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
59 |
// <clinit> with args is allowed in class file version < 51. |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
60 |
try { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
61 |
Class newClass = Class.forName("clinitArg"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
62 |
} catch (java.lang.ClassFormatError e) { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
63 |
throw new RuntimeException( |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
64 |
"Unexpected ClassFormatError exception for <clinit> with argument in class file < 51"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
65 |
} |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
66 |
|
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
67 |
// <clinit> with args is not allowed in class file version >= 51. |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
68 |
try { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
69 |
Class newClass = Class.forName("clinitArg51"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
70 |
throw new RuntimeException( |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
71 |
"Expected ClassFormatError exception for <clinit> with argument not thrown"); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
72 |
} catch (java.lang.ClassFormatError e) { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
73 |
System.out.println("Test BadInitMethod passed for <clinit> with argument"); |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
74 |
} |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
75 |
|
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
76 |
try { |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
77 |
Class newClass = Class.forName("badInit"); |
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
78 |
throw new RuntimeException( |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
79 |
"Expected ClassFormatError exception for non-void <init> not thrown"); |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
80 |
} catch (java.lang.ClassFormatError e) { |
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
31777
diff
changeset
|
81 |
System.out.println("Test BadInitMethod passed for non-void <init>"); |
31777
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
82 |
} |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
83 |
} |
0bfed49b6beb
8130669: VM prohibits <clinit> methods with return values
hseigel
parents:
diff
changeset
|
84 |
} |