67 System.out.println(cce.getMessage());
68 if (!cce.getMessage().contains("java.base/java.lang.Object cannot be cast to Derived")) {
69 throw new RuntimeException("Wrong message: " + cce.getMessage());
70 }
71 }
72 }
73
74 public static void invalidClassToString() throws Throwable {
75 // Get the java.lang.Module object for module java.base.
76 Class jlObject = Class.forName("java.lang.Object");
77 Object jlObject_jlM = jlObject.getModule();
78 assertNotNull(jlObject_jlM, "jlModule object of java.lang.Object should not be null");
79
80 // Get the class loader for CCE_module_msg and assume it's also used to
81 // load classes p1.c1 and p2.c2.
82 ClassLoader this_cldr = CCE_module_msg.class.getClassLoader();
83
84 // Define a module for p2.
85 Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
86 assertNotNull(m2x, "Module should not be null");
87 ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
88 ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
89
90 try {
91 ModuleHelper.AddModuleExportsToAll(m2x, "p2");
92 Object p2Obj = new p2.c2();
93 System.out.println((String)p2Obj);
94 throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
95 } catch (ClassCastException cce) {
96 String exception = cce.getMessage();
97 System.out.println(exception);
98 if (exception.contains("module_two/p2.c2") ||
99 !(exception.contains("module_two@") &&
100 exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) {
101 throw new RuntimeException("Wrong message: " + exception);
102 }
103 }
104 }
105
106 public static void invalidClassToStringCustomLoader() throws Throwable {
107 // Get the java.lang.Module object for module java.base.
|
67 System.out.println(cce.getMessage());
68 if (!cce.getMessage().contains("java.base/java.lang.Object cannot be cast to Derived")) {
69 throw new RuntimeException("Wrong message: " + cce.getMessage());
70 }
71 }
72 }
73
74 public static void invalidClassToString() throws Throwable {
75 // Get the java.lang.Module object for module java.base.
76 Class jlObject = Class.forName("java.lang.Object");
77 Object jlObject_jlM = jlObject.getModule();
78 assertNotNull(jlObject_jlM, "jlModule object of java.lang.Object should not be null");
79
80 // Get the class loader for CCE_module_msg and assume it's also used to
81 // load classes p1.c1 and p2.c2.
82 ClassLoader this_cldr = CCE_module_msg.class.getClassLoader();
83
84 // Define a module for p2.
85 Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
86 assertNotNull(m2x, "Module should not be null");
87 ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
88 ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
89
90 try {
91 ModuleHelper.AddModuleExportsToAll(m2x, "p2");
92 Object p2Obj = new p2.c2();
93 System.out.println((String)p2Obj);
94 throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
95 } catch (ClassCastException cce) {
96 String exception = cce.getMessage();
97 System.out.println(exception);
98 if (exception.contains("module_two/p2.c2") ||
99 !(exception.contains("module_two@") &&
100 exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) {
101 throw new RuntimeException("Wrong message: " + exception);
102 }
103 }
104 }
105
106 public static void invalidClassToStringCustomLoader() throws Throwable {
107 // Get the java.lang.Module object for module java.base.
|