< prev index next >

test/hotspot/jtreg/runtime/modules/CCE_module_msg.java

Print this page

        

@@ -46,10 +46,11 @@
     private static final Path CLASSES_DIR = Paths.get("classes");
 
     public static void main(String[] args) throws Throwable {
         // Should not display version
         invalidObjectToDerived();
+        invalidOriginalInnerToDerived();
         invalidTimeToDerived();
         invalidHeadersToDerived();
         // Should display version
         invalidClassToString();
         // Should display customer class loader

@@ -64,12 +65,29 @@
             for (int i = 0; i < 1; i += 1) {
                 left = ((Derived) instance).method(left, right);
             }
             throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
         } catch (ClassCastException cce) {
-            System.out.println(cce.getMessage());
-            if (!cce.getMessage().contains("java.base/java.lang.Object cannot be cast to Derived")) {
+            System.out.println(cce.toString());
+            if (!cce.getMessage().contains("class java.lang.Object cannot be cast to class Derived (java.lang.Object is in module java.base of loader 'bootstrap'; Derived is in unnamed module of loader 'app')")) {
+                throw new RuntimeException("Wrong message: " + cce.getMessage());
+            }
+        }
+    }
+
+    public static void invalidOriginalInnerToDerived() {
+        OriginalInner instance = new OriginalInner();
+        int left = 23;
+        int right = 42;
+        try {
+            for (int i = 0; i < 1; i += 1) {
+                left = ((Derived) (java.lang.Object)instance).method(left, right);
+            }
+            throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
+        } catch (ClassCastException cce) {
+            System.out.println(cce.toString());
+            if (!cce.getMessage().contains("class OriginalInner cannot be cast to class Derived (OriginalInner and Derived are in unnamed module of loader 'app')")) {
                 throw new RuntimeException("Wrong message: " + cce.getMessage());
             }
         }
     }
 

@@ -82,12 +100,12 @@
             for (int i = 0; i < 1; i += 1) {
                 left = ((Derived) (java.lang.Object)instance).method(left, right);
             }
             throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
         } catch (ClassCastException cce) {
-            System.out.println(cce.getMessage());
-            if (!cce.getMessage().contains("java.sql/java.sql.Time cannot be cast to Derived")) {
+            System.out.println(cce.toString());
+            if (!cce.getMessage().contains("class java.sql.Time cannot be cast to class Derived (java.sql.Time is in module java.sql of loader 'platform'; Derived is in unnamed module of loader 'app')")) {
                 throw new RuntimeException("Wrong message: " + cce.getMessage());
             }
         }
     }
 

@@ -100,12 +118,12 @@
             for (int i = 0; i < 1; i += 1) {
                 left = ((Derived) (java.lang.Object)instance).method(left, right);
             }
             throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
         } catch (ClassCastException cce) {
-            System.out.println(cce.getMessage());
-            if (!cce.getMessage().contains("jdk.httpserver/com.sun.net.httpserver.Headers cannot be cast to Derived")) {
+            System.out.println(cce.toString());
+            if (!cce.getMessage().contains("class com.sun.net.httpserver.Headers cannot be cast to class Derived (com.sun.net.httpserver.Headers is in module jdk.httpserver of loader 'platform'; Derived is in unnamed module of loader 'app')")) {
                 throw new RuntimeException("Wrong message: " + cce.getMessage());
             }
         }
     }
 

@@ -130,14 +148,13 @@
             Object p2Obj = new p2.c2();
             System.out.println((String)p2Obj);
             throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
         } catch (ClassCastException cce) {
             String exception = cce.getMessage();
-            System.out.println(exception);
-            if (exception.contains("module_two/p2.c2") ||
-                !(exception.contains("module_two@") &&
-                  exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) {
+            System.out.println(cce.toString());
+            if (!exception.contains("class p2.c2 cannot be cast to class java.lang.String (p2.c2 is in module module_two@") ||
+                !exception.contains(" of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')")) {
                 throw new RuntimeException("Wrong message: " + exception);
             }
         }
     }
 

@@ -158,18 +175,25 @@
             Object c4Obj = p4_c4_class.newInstance();
             System.out.println((String)c4Obj);
             throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
         } catch (ClassCastException cce) {
             String exception = cce.getMessage();
-            System.out.println(exception);
-            if (!exception.contains("MyClassLoader//p4.c4 cannot be cast to java.base/java.lang.String")) {
+            System.out.println(cce.toString());
+            if (!exception.contains("class p4.c4 cannot be cast to class java.lang.String (p4.c4 is in unnamed module of loader 'MyClassLoader' @") ||
+                !exception.contains("; java.lang.String is in module java.base of loader 'bootstrap')")) {
                 throw new RuntimeException("Wrong message: " + exception);
             }
         }
     }
 }
 
+class OriginalInner extends java.lang.Object {
+    public int method(int left, int right) {
+        return right;
+    }
+}
+
 class Derived extends java.lang.Object {
     public int method(int left, int right) {
         return right;
     }
 }
< prev index next >