38 throw new RuntimeException("Expected VerifyError exception not thrown"); 39 } catch (java.lang.VerifyError e) { 40 if (!e.getMessage().contains(message)) { 41 throw new RuntimeException("Wrong VerifyError: " + e.getMessage()); 42 } 43 } 44 } 45 46 public static void runTestFormatError(String test_name, String message) throws Exception { 47 System.out.println("Testing: " + test_name); 48 try { 49 Class newClass = Class.forName(test_name); 50 throw new RuntimeException("Expected ClassFormatError exception not thrown"); 51 } catch (java.lang.ClassFormatError e) { 52 if (!e.getMessage().contains(message)) { 53 throw new RuntimeException("Wrong ClassFormatError: " + e.getMessage()); 54 } 55 } 56 } 57 58 public static void main(String[] args) throws Exception { 59 60 // Test that a defaultvalue opcode with an out of bounds cp index causes a VerifyError. 61 runTestVerifyError("defValBadCP", "Illegal constant pool index"); 62 63 // Test that ClassFormatError is thrown for a class file, with major version 54, that 64 // contains a defaultvalue opcode. 65 runTestFormatError("defValBadMajorVersion", "defaultvalue not supported by this class file version"); 66 67 // Test VerifyError is thrown if a defaultvalue's cp entry is not a class. 68 runTestVerifyError("defValWrongCPType", "Illegal type at constant pool entry"); 69 70 // Test that a withfield opcode with an out of bounds cp index causes a VerifyError. 71 runTestVerifyError("wthFldBadCP", "Illegal constant pool index"); 72 73 // Test that VerifyError is thrown if the first operand on the stack is not assignable 74 // to withfield's field. 75 runTestVerifyError("wthFldBadFldVal", "Bad type on operand stack"); 76 77 // Test that VerifyError is thrown if the second operand on the stack is a primitive. 81 // contains a withfield opcode. 82 runTestFormatError("wthFldBadMajorVersion", "withfield not supported by this class file version"); 83 84 // Test VerifyError is thrown if a withfields's cp entry is not a field. 85 runTestVerifyError("wthFldWrongCPType", "Illegal type at constant pool entry"); 86 87 // Test that VerifyError is thrown if the class for a withfields's cp fieldref 88 // entry is java.lang.Object and the reference on the stack is a value type. 89 runTestVerifyError("wthFldObject", "must be identical value types"); 90 91 // Test VerifyError is thrown if a monitorenter's cp entry is a value type. 92 runTestVerifyError("monEnterVT", "Bad type on operand stack"); 93 94 // Test VerifyError is thrown if a defaultvalue's cp entry is a value type. 95 // TBD!!! 96 runTestVerifyError("defValueObj", "Invalid type on operand stack in withfield instruction"); 97 98 // Test VerifyError is thrown if a withfield's class operand is not a value type. 99 runTestVerifyError("withfieldObj", "Bad type on operand stack"); 100 101 // Test that an array of value types is not assignable to [Ljava/lang/Object; (Non-covariance). 102 runTestVerifyError("NoArrayCov", 103 "Type '[QNoArrayCov;' (current frame, stack[1]) is not assignable to '[Ljava/lang/Object;'"); 104 105 // Test that an array of value types is not assignable to an array of interfaces (Non-covariance). 106 runTestVerifyError("NoArrayCovIntf", 107 "Type '[QNoArrayCovIntf;' (current frame, stack[1]) is not assignable to '[LII;'"); 108 109 // Test that null is not assignable to a value type. 110 runTestVerifyError("NoNullVT", 111 "Type null (current frame, stack[1]) is not assignable to 'QNoNullVT;'"); 112 } 113 } | 38 throw new RuntimeException("Expected VerifyError exception not thrown"); 39 } catch (java.lang.VerifyError e) { 40 if (!e.getMessage().contains(message)) { 41 throw new RuntimeException("Wrong VerifyError: " + e.getMessage()); 42 } 43 } 44 } 45 46 public static void runTestFormatError(String test_name, String message) throws Exception { 47 System.out.println("Testing: " + test_name); 48 try { 49 Class newClass = Class.forName(test_name); 50 throw new RuntimeException("Expected ClassFormatError exception not thrown"); 51 } catch (java.lang.ClassFormatError e) { 52 if (!e.getMessage().contains(message)) { 53 throw new RuntimeException("Wrong ClassFormatError: " + e.getMessage()); 54 } 55 } 56 } 57 58 public static void runTestNoError(String test_name) throws Exception { 59 System.out.println("Testing: " + test_name); 60 Class newClass = Class.forName(test_name); 61 } 62 63 public static void main(String[] args) throws Exception { 64 65 // Test that a defaultvalue opcode with an out of bounds cp index causes a VerifyError. 66 runTestVerifyError("defValBadCP", "Illegal constant pool index"); 67 68 // Test that ClassFormatError is thrown for a class file, with major version 54, that 69 // contains a defaultvalue opcode. 70 runTestFormatError("defValBadMajorVersion", "defaultvalue not supported by this class file version"); 71 72 // Test VerifyError is thrown if a defaultvalue's cp entry is not a class. 73 runTestVerifyError("defValWrongCPType", "Illegal type at constant pool entry"); 74 75 // Test that a withfield opcode with an out of bounds cp index causes a VerifyError. 76 runTestVerifyError("wthFldBadCP", "Illegal constant pool index"); 77 78 // Test that VerifyError is thrown if the first operand on the stack is not assignable 79 // to withfield's field. 80 runTestVerifyError("wthFldBadFldVal", "Bad type on operand stack"); 81 82 // Test that VerifyError is thrown if the second operand on the stack is a primitive. 86 // contains a withfield opcode. 87 runTestFormatError("wthFldBadMajorVersion", "withfield not supported by this class file version"); 88 89 // Test VerifyError is thrown if a withfields's cp entry is not a field. 90 runTestVerifyError("wthFldWrongCPType", "Illegal type at constant pool entry"); 91 92 // Test that VerifyError is thrown if the class for a withfields's cp fieldref 93 // entry is java.lang.Object and the reference on the stack is a value type. 94 runTestVerifyError("wthFldObject", "must be identical value types"); 95 96 // Test VerifyError is thrown if a monitorenter's cp entry is a value type. 97 runTestVerifyError("monEnterVT", "Bad type on operand stack"); 98 99 // Test VerifyError is thrown if a defaultvalue's cp entry is a value type. 100 // TBD!!! 101 runTestVerifyError("defValueObj", "Invalid type on operand stack in withfield instruction"); 102 103 // Test VerifyError is thrown if a withfield's class operand is not a value type. 104 runTestVerifyError("withfieldObj", "Bad type on operand stack"); 105 106 // Test that an array of value types is assignable to [Ljava/lang/Object; (Covariance). 107 runTestNoError("NoArrayCov"); 108 109 // Test that an array of value types is assignable to an array of interfaces (Covariance). 110 runTestNoError("NoArrayCovIntf"); 111 112 // Test that null is not assignable to a value type. 113 runTestVerifyError("NoNullVT", 114 "Type null (current frame, stack[1]) is not assignable to 'QNoNullVT;'"); 115 } 116 } |