1 /* |
1 /* |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
81 // Get the class loader for CCE_module_msg and assume it's also used to |
81 // Get the class loader for CCE_module_msg and assume it's also used to |
82 // load classes p1.c1 and p2.c2. |
82 // load classes p1.c1 and p2.c2. |
83 ClassLoader this_cldr = CCE_module_msg.class.getClassLoader(); |
83 ClassLoader this_cldr = CCE_module_msg.class.getClassLoader(); |
84 |
84 |
85 // Define a module for p2. |
85 // Define a module for p2. |
86 Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" }); |
86 Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" }); |
87 assertNotNull(m2, "Module should not be null"); |
87 assertNotNull(m2x, "Module should not be null"); |
88 ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" }); |
88 ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" }); |
89 ModuleHelper.AddReadsModule(m2, jlObject_jlrM); |
89 ModuleHelper.AddReadsModule(m2x, jlObject_jlrM); |
90 |
90 |
91 try { |
91 try { |
92 ModuleHelper.AddModuleExportsToAll(m2, "p2"); |
92 ModuleHelper.AddModuleExportsToAll(m2x, "p2"); |
93 Object p2Obj = new p2.c2(); |
93 Object p2Obj = new p2.c2(); |
94 System.out.println((String)p2Obj); |
94 System.out.println((String)p2Obj); |
95 throw new RuntimeException("ClassCastException wasn't thrown, test failed."); |
95 throw new RuntimeException("ClassCastException wasn't thrown, test failed."); |
96 } catch (ClassCastException cce) { |
96 } catch (ClassCastException cce) { |
97 String exception = cce.getMessage(); |
97 String exception = cce.getMessage(); |
98 System.out.println(exception); |
98 System.out.println(exception); |
99 if (exception.contains("module2/p2.c2") || |
99 if (exception.contains("module_two/p2.c2") || |
100 !(exception.contains("module2@") && |
100 !(exception.contains("module_two@") && |
101 exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) { |
101 exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) { |
102 throw new RuntimeException("Wrong message: " + exception); |
102 throw new RuntimeException("Wrong message: " + exception); |
103 } |
103 } |
104 } |
104 } |
105 } |
105 } |