1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2019 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /** 26 * @test 27 * @summary Check that methods are printed properly. 28 * @compile -encoding UTF-8 TestPrintingMethods.java 29 * @compile TeMe3_C.jasm 30 * @run main/othervm -Xbootclasspath/a:. test.TestPrintingMethods 31 */ 32 33 package test; 34 35 public class TestPrintingMethods { 36 37 private static String expectedErrorMessage_VV = "void test.TeMe3_B.ma()"; 38 private static String expectedErrorMessage_integral = "double[][] test.TeMe3_B.ma(int, boolean, byte[][], float)"; 39 private static String expectedErrorMessage_classes = "test.TeMe3_B[][] test.TeMe3_B.ma(java.lang.Object[][][])"; 40 private static String expectedErrorMessage_unicode = "java.lang.Object test.TeMe3_B.m\u20ac\u00a3a(java.lang.Object)"; 41 checkMsg(Error e, String expected)42 static void checkMsg(Error e, String expected) throws Exception { 43 String errorMsg = e.getMessage(); 44 if (errorMsg == null) { 45 throw new RuntimeException("Caught AbstractMethodError with empty message."); 46 } else if (errorMsg.contains(expected)) { 47 System.out.println("Passed with message: " + errorMsg); 48 } else { 49 System.out.println("Expected method to be printed as \"" + expected + "\"\n" + 50 "in exception message: " + errorMsg); 51 throw new RuntimeException("Method not printed as expected."); 52 } 53 } 54 55 // Call various missing methods to check that the exception 56 // message contains the proper string for the method name and 57 // signature. We expect Java-like printing of parameters etc. test()58 static void test() throws Exception { 59 TeMe3_A c = new TeMe3_C(); 60 61 try { 62 c.ma(); 63 throw new RuntimeException("Expected AbstractMethodError was not thrown."); 64 } catch (AbstractMethodError e) { 65 checkMsg(e, expectedErrorMessage_VV); 66 } 67 68 try { 69 c.ma(2, true, new byte[2][3], 23.4f); 70 throw new RuntimeException("Expected AbstractMethodError was not thrown."); 71 } catch (AbstractMethodError e) { 72 checkMsg(e, expectedErrorMessage_integral); 73 } 74 75 try { 76 c.ma(new java.lang.Object[1][2][3]); 77 throw new RuntimeException("Expected AbstractMethodError was not thrown."); 78 } catch (AbstractMethodError e) { 79 checkMsg(e, expectedErrorMessage_classes); 80 } 81 82 try { 83 c.m\u20ac\u00a3a(new java.lang.Object()); 84 throw new RuntimeException("Expected AbstractMethodError was not thrown."); 85 } catch (AbstractMethodError e) { 86 checkMsg(e, expectedErrorMessage_unicode); 87 } 88 } 89 main(String[] args)90 public static void main(String[] args) throws Exception { 91 test(); 92 } 93 } 94 95 // Helper classes to test abstract method error. 96 // 97 // Errorneous versions of these classes are implemented in java 98 // assembler. 99 100 101 // ----------------------------------------------------------------------- 102 // Test AbstractMethod error shadowing existing implementation. 103 // 104 // Class hierachy: 105 // 106 // A // A class implementing m() and similar. 107 // | 108 // B // An abstract class defining m() abstract. 109 // | 110 // C // An errorneous class lacking an implementation of m(). 111 // 112 class TeMe3_A { ma()113 public void ma() { 114 System.out.print("A.ma()"); 115 } ma(int i, boolean z, byte[][] b, float f)116 public double[][] ma(int i, boolean z, byte[][] b, float f) { 117 return null; 118 } ma(java.lang.Object[][][] o)119 public TeMe3_B[][] ma(java.lang.Object[][][] o) { 120 return null; 121 } u00a3a(java.lang.Object s)122 public java.lang.Object m\u20ac\u00a3a(java.lang.Object s) { 123 return null; 124 } 125 } 126 127 abstract class TeMe3_B extends TeMe3_A { ma()128 public abstract void ma(); ma(int i, boolean z, byte[][] b, float f)129 public abstract double[][] ma(int i, boolean z, byte[][] b, float f); ma(java.lang.Object[][][] o)130 public abstract TeMe3_B[][] ma(java.lang.Object[][][] o); u00a3a(java.lang.Object s)131 public abstract java.lang.Object m\u20ac\u00a3a(java.lang.Object s); 132 } 133 134 // An errorneous version of this class is implemented in java 135 // assembler. 136 class TeMe3_C extends TeMe3_B { 137 // These methods are missing in the .jasm implementation. ma()138 public void ma() { 139 System.out.print("C.ma()"); 140 } ma(int i, boolean z, byte[][] b, float f)141 public double[][] ma(int i, boolean z, byte[][] b, float f) { 142 return new double[2][2]; 143 } ma(java.lang.Object[][][] o)144 public TeMe3_B[][] ma(java.lang.Object[][][] o) { 145 return new TeMe3_C[3][3]; 146 } u00a3a(java.lang.Object s)147 public java.lang.Object m\u20ac\u00a3a(java.lang.Object s) { 148 return new java.lang.Object(); 149 } 150 } 151 152