test/hotspot/jtreg/runtime/modules/CCE_module_msg.java
changeset 50569 60d66a249db6
parent 48791 6e079ff6c83c
child 50761 cb07f4b539fc
--- a/test/hotspot/jtreg/runtime/modules/CCE_module_msg.java	Thu Jun 14 05:50:21 2018 -0700
+++ b/test/hotspot/jtreg/runtime/modules/CCE_module_msg.java	Thu Jun 14 10:33:54 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,6 +48,8 @@
     public static void main(String[] args) throws Throwable {
         // Should not display version
         invalidObjectToDerived();
+        invalidTimeToDerived();
+        invalidHeadersToDerived();
         // Should display version
         invalidClassToString();
         // Should display customer class loader
@@ -71,6 +73,42 @@
         }
     }
 
+    // Test with a non-upgradeable 'java.' module other than java.base.
+    public static void invalidTimeToDerived() {
+        java.sql.Time instance = new java.sql.Time(10000);
+        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.getMessage());
+            if (!cce.getMessage().contains("java.sql/java.sql.Time cannot be cast to Derived")) {
+                throw new RuntimeException("Wrong message: " + cce.getMessage());
+            }
+        }
+    }
+
+    // Test with a non-upgradeable 'jdk.' module.
+    public static void invalidHeadersToDerived() {
+        com.sun.net.httpserver.Headers instance = new com.sun.net.httpserver.Headers();
+        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.getMessage());
+            if (!cce.getMessage().contains("jdk.httpserver/com.sun.net.httpserver.Headers cannot be cast to Derived")) {
+                throw new RuntimeException("Wrong message: " + cce.getMessage());
+            }
+        }
+    }
+
     public static void invalidClassToString() throws Throwable {
         // Get the java.lang.Module object for module java.base.
         Class jlObject = Class.forName("java.lang.Object");