hotspot/test/runtime/modules/JVMDefineModule.java
author alanb
Fri, 10 Feb 2017 09:03:55 +0000
changeset 43665 4bb003cad9b9
parent 43446 4f9ac7ab99d9
child 44520 0553e129e0ec
child 46322 25836096c89d
permissions -rw-r--r--
8173393: Module system implementation refresh (2/2017) Reviewed-by: lfoltan, acorn, mchung Contributed-by: alan.bateman@oracle.com, george.triantafillou@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43665
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43446
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    23
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    26
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40020
diff changeset
    27
 * @library /test/lib ..
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @build sun.hotspot.WhiteBox
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @compile/module=java.base java/lang/reflect/ModuleHelper.java
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMDefineModule
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import static jdk.test.lib.Asserts.*;
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
    36
import java.sql.Time;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
public class JVMDefineModule {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
    public static void main(String args[]) throws Throwable {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
        MyClassLoader cl = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        Object m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
        // NULL classloader argument, expect success
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        m = ModuleHelper.ModuleObject("mymodule", null, new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
/* Invalid test, won't compile.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        // Invalid classloader argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        try {
43665
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43446
diff changeset
    52
            m = ModuleHelper.ModuleObject("mymodule_one", new Object(), new String[] { "mypackage1" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            ModuleHelper.DefineModule(m,  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
            throw new RuntimeException("Failed to get expected IAE for bad loader");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
*/
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        // NULL package argument, should not throw an exception
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
    61
        m = ModuleHelper.ModuleObject("mymoduleTwo", cl, new String[] { "nullpkg" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
    63
        ModuleHelper.DefineModule(m, "9.0", "mymoduleTwo/here", null);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        // Null module argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            ModuleHelper.DefineModule(null,  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            throw new RuntimeException("Failed to get expected NPE for null module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            if (!e.getMessage().contains("Null module object")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
              throw new RuntimeException("Failed to get expected IAE message for null module: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        // Invalid module argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            ModuleHelper.DefineModule(new Object(),  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            throw new RuntimeException("Failed to get expected IAE or NPE for bad module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        } catch(IllegalArgumentException e) {
40020
20738e6bef83 8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
lfoltan
parents: 38152
diff changeset
    81
            if (!e.getMessage().contains("module is not an instance of type java.lang.reflect.Module")) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
              throw new RuntimeException("Failed to get expected IAE message for bad module: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        // NULL module name, expect an IAE or NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            m = ModuleHelper.ModuleObject(null, cl, new String[] { "mypackage2" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage2" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            throw new RuntimeException("Failed to get expected NPE for NULL module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        // module name is java.base, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        m = ModuleHelper.ModuleObject("java.base", cl, new String[] { "mypackage3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            throw new RuntimeException("Failed to get expected IAE for java.base, not defined with boot class loader");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            if (!e.getMessage().contains("Class loader must be the boot class loader")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
              throw new RuntimeException("Failed to get expected IAE message for java.base: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        // Duplicates in package list, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        m = ModuleHelper.ModuleObject("module.x", cl, new String[] { "mypackage4", "mypackage5" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage4", "mypackage5", "mypackage4" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            throw new RuntimeException("Failed to get IAE for duplicate packages");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
            if (!e.getMessage().contains("Duplicate package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
              throw new RuntimeException("Failed to get expected IAE message for duplicate package: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        // Empty entry in package list, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        m = ModuleHelper.ModuleObject("module.y", cl, new String[] { "mypackageX", "mypackageY" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackageX", "", "mypackageY" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            throw new RuntimeException("Failed to get IAE for empty package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
              throw new RuntimeException("Failed to get expected IAE message empty package entry: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   130
        // Duplicate module name, expect an ISE
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   131
        m = ModuleHelper.ModuleObject("Module_A", cl, new String[] { "mypackage6" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6a" });
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   136
            throw new RuntimeException("Failed to get ISE for duplicate module");
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   137
        } catch(IllegalStateException e) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   138
            if (!e.getMessage().contains("Module Module_A is already defined")) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   139
              throw new RuntimeException("Failed to get expected ISE message for duplicate module: " + e.getMessage());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   142
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   143
        // Package is already defined for class loader, expect an ISE
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        m = ModuleHelper.ModuleObject("dupl.pkg.module", cl, new String[] { "mypackage6b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
43446
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   147
            throw new RuntimeException("Failed to get ISE for existing package");
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   148
        } catch(IllegalStateException e) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   149
            if (!e.getMessage().contains("Package mypackage6 for module dupl.pkg.module is already in another module, Module_A, defined to the class loader")) {
4f9ac7ab99d9 8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents: 42630
diff changeset
   150
              throw new RuntimeException("Failed to get expected ISE message for duplicate package: " + e.getMessage());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   153
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        // Empty module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            m = ModuleHelper.ModuleObject("", cl, new String[] { "mypackage8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            throw new RuntimeException("Failed to get expected IAE for empty module name");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   163
        // Module name with ';', not allowed in java source
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            m = ModuleHelper.ModuleObject("bad;name", cl, new String[] { "mypackage9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   166
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            throw new RuntimeException("Failed to get expected IAE for bad;name");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   172
        // Module name with leading dot, not allowed in java source
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            m = ModuleHelper.ModuleObject(".leadingdot", cl, new String[] { "mypackage9a" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9a" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            throw new RuntimeException("Failed to get expected IAE for .leadingdot");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   180
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   181
        // Module name with trailing dot, not allowed in java source
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            throw new RuntimeException("Failed to get expected IAE for trailingdot.");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   190
        // Module name with consecutive dots, not allowed in java source
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        try {
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   192
            m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   193
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   194
            throw new RuntimeException("Failed to get expected IAE for trailingdot.");
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        // module name with multiple dots, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        m = ModuleHelper.ModuleObject("more.than.one.dat", cl, new String[] { "mypackage9d" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9d" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        // Zero length package list, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        m = ModuleHelper.ModuleObject("zero.packages", cl, new String[] { });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        // Invalid package name, expect an IAE
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   210
        m = ModuleHelper.ModuleObject("moduleFive", cl, new String[] { "your.package" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "your.package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            throw new RuntimeException("Failed to get expected IAE for your.package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   219
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        // Invalid package name, expect an IAE
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   221
        m = ModuleHelper.ModuleObject("moduleSix", cl, new String[] { "foo" }); // Name irrelevant
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { ";your/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            throw new RuntimeException("Failed to get expected IAE for ;your.package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   230
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        // Invalid package name, expect an IAE
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   232
        m = ModuleHelper.ModuleObject("moduleSeven", cl, new String[] { "foo" }); // Name irrelevant
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "7[743" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            throw new RuntimeException("Failed to get expected IAE for package 7[743");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   241
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   242
        // Package named "java" defined to a class loader other than the boot or platform class loader, expect an IAE
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   243
        m = ModuleHelper.ModuleObject("modulejavapkgOne", cl, new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   244
        try {
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   245
            // module m is defined to an instance of MyClassLoader class loader
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   246
            ModuleHelper.DefineModule(m, "9.0", "modulejavapkgOne", new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   247
            throw new RuntimeException("Failed to get expected IAE for package java/foo");
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   248
        } catch(IllegalArgumentException e) {
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   249
            if (!e.getMessage().contains("prohibited package name")) {
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   250
              throw new RuntimeException("Failed to get expected IAE message for prohibited package name: " + e.getMessage());
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   251
            }
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   252
        }
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   253
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   254
        // Package named "javabar" defined to a class loader other than the boot or platform class loader, should be ok
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   255
        m = ModuleHelper.ModuleObject("modulejavapkgTwo", cl, new String[] { "javabar" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   256
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   257
        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgTwo", new String[] { "javabar" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   258
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   259
        // Package named "java" defined to the boot class loader, should be ok
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   260
        //   m's type is a java.lang.Object, module is java.base
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   261
        //   java.base module is defined to the boot loader
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   262
        ClassLoader boot_loader = m.getClass().getClassLoader();
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   263
        m = ModuleHelper.ModuleObject("modulejavapkgThree", boot_loader, new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   264
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   265
        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgThree", new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   266
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   267
        // Package named "java" defined to the platform class loader, should be ok
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   268
        //   java.sql module defined to the platform class loader.
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   269
        java.sql.Time jst = new java.sql.Time(45 * 1000);
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   270
        ClassLoader platform_loader = jst.getClass().getClassLoader();
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   271
        m = ModuleHelper.ModuleObject("modulejavapkgFour", platform_loader, new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   272
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   273
        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgFour", new String[] { "java/foo" });
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
   274
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        // module version that is null, should be okay
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   276
        m = ModuleHelper.ModuleObject("moduleEight", cl, new String[] { "a_package_8" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   278
        ModuleHelper.DefineModule(m, null, "moduleEight/here", new String[] { "a_package_8" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   279
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        // module version that is "", should be okay
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   281
        m = ModuleHelper.ModuleObject("moduleNine", cl, new String[] { "a_package_9" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        assertNotNull(m, "Module should not be null");
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   283
        ModuleHelper.DefineModule(m, "", "moduleNine/here", new String[] { "a_package_9" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   284
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        // module location that is null, should be okay
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   286
        m = ModuleHelper.ModuleObject("moduleTen", cl, new String[] { "a_package_10" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        ModuleHelper.DefineModule(m, "9.0", null, new String[] { "a_package_10" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   289
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        // module location that is "", should be okay
42630
ae91fbc4b59f 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42307
diff changeset
   291
        m = ModuleHelper.ModuleObject("moduleEleven", cl, new String[] { "a_package_11" });
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        ModuleHelper.DefineModule(m, "9.0", "", new String[] { "a_package_11" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   294
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   295
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    static class MyClassLoader extends ClassLoader { }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   297
}