24 |
24 |
25 /* |
25 /* |
26 * @test |
26 * @test |
27 * @bug 8130669 |
27 * @bug 8130669 |
28 * @summary VM prohibits <clinit> methods with return values |
28 * @summary VM prohibits <clinit> methods with return values |
29 * @compile ignoredClinit.jasm |
29 * @compile nonvoidClinit.jasm |
|
30 * @compile clinitNonStatic.jasm |
|
31 * @compile clinitArg.jasm |
|
32 * @compile clinitArg51.jasm |
30 * @compile badInit.jasm |
33 * @compile badInit.jasm |
31 * @run main/othervm -Xverify:all BadInitMethod |
34 * @run main/othervm -Xverify:all BadInitMethod |
32 */ |
35 */ |
33 |
36 |
34 // Test that a non-void <clinit> method does not cause an exception to be |
37 // Test that non-void <clinit>, non-static <clinit>, and non-void |
35 // thrown. But that a non-void <init> method causes a ClassFormatError |
38 // <init> methods cause ClassFormatException's to be thrown. |
36 // exception. |
|
37 public class BadInitMethod { |
39 public class BadInitMethod { |
38 public static void main(String args[]) throws Throwable { |
40 public static void main(String args[]) throws Throwable { |
39 |
41 |
40 System.out.println("Regression test for bug 8130669"); |
42 System.out.println("Regression test for bug 8130669"); |
41 try { |
43 try { |
42 Class newClass = Class.forName("ignoredClinit"); |
44 Class newClass = Class.forName("nonvoidClinit"); |
43 } catch (java.lang.Throwable e) { |
45 throw new RuntimeException( |
44 throw new RuntimeException("Unexpected exception: " + e.getMessage()); |
46 "Expected ClassFormatError exception for non-void <clinit> not thrown"); |
|
47 } catch (java.lang.ClassFormatError e) { |
|
48 System.out.println("Test BadInitMethod passed for non-void <clinit>"); |
|
49 } |
|
50 |
|
51 try { |
|
52 Class newClass = Class.forName("clinitNonStatic"); |
|
53 throw new RuntimeException( |
|
54 "Expected ClassFormatError exception for non-static <clinit> not thrown"); |
|
55 } catch (java.lang.ClassFormatError e) { |
|
56 System.out.println("Test BadInitMethod passed for non-static <clinit>"); |
|
57 } |
|
58 |
|
59 // <clinit> with args is allowed in class file version < 51. |
|
60 try { |
|
61 Class newClass = Class.forName("clinitArg"); |
|
62 } catch (java.lang.ClassFormatError e) { |
|
63 throw new RuntimeException( |
|
64 "Unexpected ClassFormatError exception for <clinit> with argument in class file < 51"); |
|
65 } |
|
66 |
|
67 // <clinit> with args is not allowed in class file version >= 51. |
|
68 try { |
|
69 Class newClass = Class.forName("clinitArg51"); |
|
70 throw new RuntimeException( |
|
71 "Expected ClassFormatError exception for <clinit> with argument not thrown"); |
|
72 } catch (java.lang.ClassFormatError e) { |
|
73 System.out.println("Test BadInitMethod passed for <clinit> with argument"); |
45 } |
74 } |
46 |
75 |
47 try { |
76 try { |
48 Class newClass = Class.forName("badInit"); |
77 Class newClass = Class.forName("badInit"); |
49 throw new RuntimeException("Expected ClassFormatError exception not thrown"); |
78 throw new RuntimeException( |
|
79 "Expected ClassFormatError exception for non-void <init> not thrown"); |
50 } catch (java.lang.ClassFormatError e) { |
80 } catch (java.lang.ClassFormatError e) { |
51 System.out.println("Test BadInitMethod passed"); |
81 System.out.println("Test BadInitMethod passed for non-void <init>"); |
52 } |
82 } |
53 } |
83 } |
54 } |
84 } |