hotspot/test/runtime/modules/JVMDefineModule.java
author jdv
Tue, 09 Aug 2016 13:45:17 +0530
changeset 40432 6a878eae7459
parent 38152 80e5da81fb2c
child 40020 20738e6bef83
permissions -rw-r--r--
8160456: KSS : resource loading issue in TIFFMetadataFormat.java Reviewed-by: prr, bpb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /testlibrary  /test/lib /compiler/whitebox ..
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.*;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
public class JVMDefineModule {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
    public static void main(String args[]) throws Throwable {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
        MyClassLoader cl = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
        Object m;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        // NULL classloader argument, expect success
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
        m = ModuleHelper.ModuleObject("mymodule", null, new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
/* Invalid test, won't compile.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        // Invalid classloader argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
            m = ModuleHelper.ModuleObject("mymodule1", new Object(), new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
            ModuleHelper.DefineModule(m,  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            throw new RuntimeException("Failed to get expected IAE for bad loader");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        }
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
        // NULL package argument, should not throw an exception
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        m = ModuleHelper.ModuleObject("mymodule2", cl, new String[] { "nullpkg" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        ModuleHelper.DefineModule(m, "9.0", "mymodule2/here", null);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        // Null module argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            ModuleHelper.DefineModule(null,  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            throw new RuntimeException("Failed to get expected NPE for null module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            if (!e.getMessage().contains("Null module object")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
              throw new RuntimeException("Failed to get expected IAE message for null module: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        // Invalid module argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            ModuleHelper.DefineModule(new Object(),  "9.0", "mymodule/here", new String[] { "mypackage1" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            throw new RuntimeException("Failed to get expected IAE or NPE for bad module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            if (!e.getMessage().contains("module is not a subclass")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
              throw new RuntimeException("Failed to get expected IAE message for bad module: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            }
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
        // NULL module name, expect an IAE or NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            m = ModuleHelper.ModuleObject(null, cl, new String[] { "mypackage2" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage2" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            throw new RuntimeException("Failed to get expected NPE for NULL module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        // module name is java.base, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        m = ModuleHelper.ModuleObject("java.base", cl, new String[] { "mypackage3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            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
   101
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            if (!e.getMessage().contains("Class loader must be the boot class loader")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
              throw new RuntimeException("Failed to get expected IAE message for java.base: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            }
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
        // Duplicates in package list, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        m = ModuleHelper.ModuleObject("module.x", cl, new String[] { "mypackage4", "mypackage5" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage4", "mypackage5", "mypackage4" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            throw new RuntimeException("Failed to get IAE for duplicate packages");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            if (!e.getMessage().contains("Duplicate package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
              throw new RuntimeException("Failed to get expected IAE message for duplicate package: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            }
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
        // Empty entry in package list, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        m = ModuleHelper.ModuleObject("module.y", cl, new String[] { "mypackageX", "mypackageY" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackageX", "", "mypackageY" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            throw new RuntimeException("Failed to get IAE for empty package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
              throw new RuntimeException("Failed to get expected IAE message empty package entry: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            }
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
        // Duplicate module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        m = ModuleHelper.ModuleObject("module.name", cl, new String[] { "mypackage6" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6a" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            throw new RuntimeException("Failed to get IAE for duplicate module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
            if (!e.getMessage().contains("Module module.name is already defined")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
              throw new RuntimeException("Failed to get expected IAE message for duplicate module: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
            }
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
        // Package is already defined for class loader, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        m = ModuleHelper.ModuleObject("dupl.pkg.module", cl, new String[] { "mypackage6b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            throw new RuntimeException("Failed to get IAE for existing package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            if (!e.getMessage().contains("Package mypackage6 for module dupl.pkg.module already exists for class loader")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
              throw new RuntimeException("Failed to get expected IAE message for duplicate package: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            }
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
        // Empty module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            m = ModuleHelper.ModuleObject("", cl, new String[] { "mypackage8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            throw new RuntimeException("Failed to get expected IAE for empty module name");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        // Bad module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            m = ModuleHelper.ModuleObject("bad;name", cl, new String[] { "mypackage9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   166
            throw new RuntimeException("Failed to get expected IAE for bad;name");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   168
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        // Bad module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            m = ModuleHelper.ModuleObject(".leadingdot", cl, new String[] { "mypackage9a" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9a" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
            throw new RuntimeException("Failed to get expected IAE for .leadingdot");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   179
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        // Bad module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            throw new RuntimeException("Failed to get expected IAE for trailingdot.");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        // Bad module name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        m = ModuleHelper.ModuleObject("consecutive..dots", cl, new String[] { "mypackage9c" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9c" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   193
            throw new RuntimeException("Failed to get expected IAE for consecutive..dots");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        // module name with multiple dots, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        m = ModuleHelper.ModuleObject("more.than.one.dat", cl, new String[] { "mypackage9d" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9d" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        // Zero length package list, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        m = ModuleHelper.ModuleObject("zero.packages", cl, new String[] { });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        m = ModuleHelper.ModuleObject("module5", cl, new String[] { "your.package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "your.package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            throw new RuntimeException("Failed to get expected IAE for your.package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   214
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   215
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
            }
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
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        m = ModuleHelper.ModuleObject("module6", cl, new String[] { "foo" }); // Name irrelevant
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { ";your/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            throw new RuntimeException("Failed to get expected IAE for ;your.package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
            }
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
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        m = ModuleHelper.ModuleObject("module7", cl, new String[] { "foo" }); // Name irrelevant
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "7[743" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            throw new RuntimeException("Failed to get expected IAE for package 7[743");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            if (!e.getMessage().contains("Invalid package name")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
              throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            }
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
        // module version that is null, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        m = ModuleHelper.ModuleObject("module8", cl, new String[] { "a_package_8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        ModuleHelper.DefineModule(m, null, "module8/here", new String[] { "a_package_8" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   245
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        // module version that is "", should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        m = ModuleHelper.ModuleObject("module9", cl, new String[] { "a_package_9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        ModuleHelper.DefineModule(m, "", "module9/here", new String[] { "a_package_9" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   250
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        // module location that is null, should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        m = ModuleHelper.ModuleObject("module10", cl, new String[] { "a_package_10" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        ModuleHelper.DefineModule(m, "9.0", null, new String[] { "a_package_10" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   255
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        // module location that is "", should be okay
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        m = ModuleHelper.ModuleObject("module11", cl, new String[] { "a_package_11" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        assertNotNull(m, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        ModuleHelper.DefineModule(m, "9.0", "", new String[] { "a_package_11" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   260
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   261
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   262
    static class MyClassLoader extends ClassLoader { }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   263
}