jdk/test/java/lang/instrument/RedefineModuleTest.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 44423 306c020eb154
child 45652 33342314ce89
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     1
/*
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     4
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     8
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    13
 * accompanied this code).
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    14
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    18
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    21
 * questions.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    22
 */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    23
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    24
/**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    25
 * @test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    26
 * @summary Basic test for redefineModule
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 42338
diff changeset
    27
 *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    28
 * @build java.base/java.lang.TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    29
 *        java.base/jdk.internal.test.TestProviderImpl1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    30
 *        java.base/jdk.internal.test.TestProviderImpl2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    31
 * @run shell MakeJAR3.sh RedefineModuleAgent
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    32
 * @run testng/othervm -javaagent:RedefineModuleAgent.jar RedefineModuleTest
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    33
 */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    34
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    35
import java.lang.TestProvider;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    36
import java.lang.instrument.Instrumentation;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    37
import java.net.URLStreamHandler;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    38
import java.net.spi.URLStreamHandlerProvider;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    39
import java.nio.file.FileSystems;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    40
import java.util.ArrayList;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    41
import java.util.Collection;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    42
import java.util.HashMap;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    43
import java.util.HashSet;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    44
import java.util.List;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    45
import java.util.Map;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    46
import java.util.ServiceLoader;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    47
import java.util.Set;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    48
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    49
import org.testng.annotations.Test;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    50
import static org.testng.Assert.*;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    51
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    52
@Test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    53
public class RedefineModuleTest {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    54
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    55
    static void redefineModule(Module module,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    56
                               Set<Module> extraReads,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    57
                               Map<String, Set<Module>> extraExports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    58
                               Map<String, Set<Module>> extraOpens,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    59
                               Set<Class<?>> extraUses,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    60
                               Map<Class<?>, List<Class<?>>> extraProvides) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    61
        RedefineModuleAgent.redefineModule(module,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    62
                                           extraReads,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    63
                                           extraExports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    64
                                           extraOpens,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    65
                                           extraUses,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    66
                                           extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    67
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    68
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
    69
    static boolean isModifiableModule(Module module) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
    70
        return RedefineModuleAgent.isModifiableModule(module);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
    71
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
    72
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    73
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    74
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    75
     * Use redefineModule to update java.base to read java.instrument
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    76
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    77
    public void testAddReads() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    78
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    79
        Module instrumentModule = Instrumentation.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    80
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    81
        // pre-conditions
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    82
        assertFalse(baseModule.canRead(instrumentModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    83
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    84
        // update java.base to read java.instrument
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    85
        Set<Module> extraReads = Set.of(instrumentModule);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    86
        redefineModule(baseModule, extraReads, Map.of(), Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    87
        assertTrue(baseModule.canRead(instrumentModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    88
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    89
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    90
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    91
     * Use redefineModule to update java.base to export jdk.internal.misc
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    92
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    93
    public void testAddExports() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    94
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    95
        Module thisModule = this.getClass().getClassLoader().getUnnamedModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    96
        String pkg = "jdk.internal.misc";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    97
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    98
        // pre-conditions
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    99
        assertFalse(baseModule.isExported(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   100
        assertFalse(baseModule.isExported(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   101
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   102
        // update java.base to export jdk.internal.misc to an unnamed module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   103
        Map<String, Set<Module>> extraExports = Map.of(pkg, Set.of(thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   104
        redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   105
        assertFalse(baseModule.isExported(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   106
        assertTrue(baseModule.isExported(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   107
        assertFalse(baseModule.isOpen(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   108
        assertFalse(baseModule.isOpen(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   109
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   110
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   111
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   112
     * Use redefineModule to update java.base to open jdk.internal.loader
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   113
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   114
    public void testAddOpens() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   115
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   116
        Module thisModule = this.getClass().getClassLoader().getUnnamedModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   117
        String pkg = "jdk.internal.loader";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   118
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   119
        // pre-conditions
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   120
        assertFalse(baseModule.isOpen(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   121
        assertFalse(baseModule.isOpen(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   122
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   123
        // update java.base to open dk.internal.loader to an unnamed module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   124
        Map<String, Set<Module>> extraExports = Map.of(pkg, Set.of(thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   125
        redefineModule(baseModule, Set.of(), Map.of(), extraExports, Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   126
        assertFalse(baseModule.isExported(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   127
        assertTrue(baseModule.isExported(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   128
        assertFalse(baseModule.isOpen(pkg));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   129
        assertTrue(baseModule.isOpen(pkg, thisModule));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   130
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   131
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   132
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   133
     * Use redefineModule to update java.base to use TestProvider and
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   134
     * provide implementations of TestProvider.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   135
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   136
    public void testAddUsesAndProvides() throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   137
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   138
        Class<TestProvider> service = TestProvider.class;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   139
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   140
        // pre-conditions
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   141
        assertFalse(baseModule.canUse(service));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   142
        assertTrue(collect(ServiceLoader.load(service)).isEmpty());
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   143
        assertTrue(collect(ServiceLoader.load(ModuleLayer.boot(), service)).isEmpty());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   144
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   145
        // update java.base to use TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   146
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(service), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   147
        assertTrue(baseModule.canUse(service));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   148
        assertTrue(collect(ServiceLoader.load(service)).isEmpty());
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   149
        assertTrue(collect(ServiceLoader.load(ModuleLayer.boot(), service)).isEmpty());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   150
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   151
        // update java.base to provide an implementation of TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   152
        Class<?> type1 = Class.forName("jdk.internal.test.TestProviderImpl1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   153
        Map<Class<?>, List<Class<?>>> extraProvides = Map.of(service, List.of(type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   154
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   155
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   156
        // invoke ServiceLoader from java.base to find providers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   157
        Set<TestProvider> providers = collect(TestProvider.providers());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   158
        assertTrue(providers.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   159
        assertTrue(containsInstanceOf(providers, type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   160
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   161
        // use ServiceLoader to load implementations visible via TCCL
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   162
        providers = collect(ServiceLoader.load(service));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   163
        assertTrue(collect(providers).size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   164
        assertTrue(containsInstanceOf(collect(providers), type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   165
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   166
        // use ServiceLoader to load implementations in the boot layer
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   167
        providers = collect(ServiceLoader.load(ModuleLayer.boot(), service));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   168
        assertTrue(collect(providers).size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   169
        assertTrue(containsInstanceOf(collect(providers), type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   170
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   171
        // update java.base to provide a second implementation of TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   172
        Class<?> type2 = Class.forName("jdk.internal.test.TestProviderImpl2");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   173
        extraProvides = Map.of(service, List.of(type2));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   174
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   175
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   176
        // invoke ServiceLoader from java.base to find providers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   177
        providers = collect(TestProvider.providers());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   178
        assertTrue(providers.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   179
        assertTrue(containsInstanceOf(providers, type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   180
        assertTrue(containsInstanceOf(providers, type2));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   181
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   182
        // use ServiceLoader to load implementations visible via TCCL
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   183
        providers = collect(ServiceLoader.load(service));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   184
        assertTrue(collect(providers).size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   185
        assertTrue(containsInstanceOf(providers, type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   186
        assertTrue(containsInstanceOf(providers, type2));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   187
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   188
        // use ServiceLoader to load implementations in the boot layer
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   189
        providers = collect(ServiceLoader.load(ModuleLayer.boot(), service));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   190
        assertTrue(collect(providers).size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   191
        assertTrue(containsInstanceOf(providers, type1));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   192
        assertTrue(containsInstanceOf(providers, type2));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   193
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   194
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   195
    private <S> Set<S> collect(Iterable<S> sl) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   196
        Set<S> providers = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   197
        sl.forEach(providers::add);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   198
        return providers;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   199
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   200
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   201
    private boolean containsInstanceOf(Collection<?> c, Class<?> type) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   202
        for (Object o : c) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   203
            if (type.isInstance(o)) return true;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   204
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   205
        return false;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   206
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   207
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   208
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   209
    public void testExportPackageToEmptySet() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   210
        // attempt to update java.base to export jdk.internal.misc to nobody
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   211
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   212
        Map<String, Set<Module>> extraExports = Map.of("jdk.internal.misc", Set.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   213
        redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   214
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   215
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   216
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   217
    public void testOpenPackageToEmptySet() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   218
        // attempt to update java.base to open jdk.internal.misc to nobody
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   219
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   220
        Map<String, Set<Module>> extraOpens = Map.of("jdk.internal.misc", Set.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   221
        redefineModule(baseModule, Set.of(), Map.of(), extraOpens, Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   222
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   223
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   224
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   225
    public void testProvideServiceWithEmptyList() throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   226
        // update java.base to provide an empty list of TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   227
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   228
        Class<?> service = TestProvider.class;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   229
        Map<Class<?>, List<Class<?>>> extraProvides = Map.of(service, List.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   230
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   231
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   232
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   233
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   234
     * Test redefineClass by attempting to update java.base to export a package
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   235
     * that it does not contain.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   236
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   237
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   238
    public void testExportPackageNotInModule() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   239
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   240
        String pkg = "jdk.doesnotexist";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   241
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   242
        // attempt to update java.base to export jdk.doesnotexist
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   243
        Map<String, Set<Module>> extraExports = Map.of(pkg, Set.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   244
        redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   245
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   246
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   247
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   248
     * Test redefineClass by attempting to update java.base to provide a service
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   249
     * where the service provider class is not in the module.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   250
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   251
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   252
    public void testProvideServiceNotInModule() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   253
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   254
        class MyProvider extends URLStreamHandlerProvider {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   255
            @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   256
            public URLStreamHandler createURLStreamHandler(String protocol) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   257
                return null;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   258
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   259
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   260
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   261
        // attempt to update java.base to provide MyProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   262
        Map<Class<?>, List<Class<?>>> extraProvides
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   263
            = Map.of(URLStreamHandlerProvider.class, List.of(MyProvider.class));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   264
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   265
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   266
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   267
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   268
     * Test redefineClass by attempting to update java.base to provide a
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   269
     * service where the service provider class is not a sub-type.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   270
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   271
    @Test(expectedExceptions = IllegalArgumentException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   272
    public void testProvideServiceNotSubtype() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   273
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   274
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   275
        Class<?> service = TestProvider.class;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   276
        Class<?> impl = FileSystems.getDefault().provider().getClass();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   277
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   278
        // attempt to update java.base to provide an implementation of TestProvider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   279
        Map<Class<?>, List<Class<?>>> extraProvides = Map.of(service, List.of(impl));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   280
        redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   281
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   282
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   283
    /**
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   284
     * Exercise IsModifiableModule
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   285
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   286
    @Test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   287
    public void testIsModifiableModule() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   288
        ClassLoader pcl = ClassLoader.getPlatformClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   289
        ClassLoader scl = ClassLoader.getSystemClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   290
        assertTrue(isModifiableModule(pcl.getUnnamedModule()));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   291
        assertTrue(isModifiableModule(scl.getUnnamedModule()));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   292
        assertTrue(isModifiableModule(RedefineModuleTest.class.getModule()));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   293
        assertTrue(isModifiableModule(Object.class.getModule()));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   294
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   295
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44423
diff changeset
   296
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   297
     * Test redefineClass with null
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   298
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   299
    public void testNulls() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   300
        Module baseModule = Object.class.getModule();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   301
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   302
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   303
            redefineModule(null, Set.of(), Map.of(), Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   304
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   305
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   306
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   307
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   308
            redefineModule(baseModule, null, Map.of(), Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   309
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   310
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   311
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   312
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   313
            redefineModule(baseModule, Set.of(), null, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   314
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   315
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   316
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   317
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   318
            redefineModule(baseModule, Set.of(), Map.of(), null, Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   319
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   320
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   321
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   322
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   323
            redefineModule(baseModule, Set.of(), Map.of(), Map.of(), null, Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   324
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   325
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   326
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   327
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   328
            redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   329
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   330
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   331
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   332
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   333
            Set<Module> containsNull = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   334
            containsNull.add(null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   335
            redefineModule(baseModule, containsNull, Map.of(), Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   336
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   337
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   339
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   340
            Map<String, Set<Module>> extraExports = new HashMap<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   341
            extraExports.put(null, Set.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   342
            redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   343
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   344
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   345
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   346
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   347
            Map<String, Set<Module>> extraExports = new HashMap<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   348
            extraExports.put(null, Set.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   349
            redefineModule(baseModule, Set.of(), Map.of(), extraExports, Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   350
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   351
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   352
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   353
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   354
            Set<Module> containsNull = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   355
            containsNull.add(null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   356
            Map<String, Set<Module>> extraExports = Map.of("java.lang", containsNull);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   357
            redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   358
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   359
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   360
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   361
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   362
            Set<Class<?>> containsNull = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   363
            containsNull.add(null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   364
            redefineModule(baseModule, Set.of(), Map.of(), Map.of(), containsNull, Map.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   365
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   366
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   367
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   368
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   369
            Map<Class<?>, List<Class<?>>> extraProvides = new HashMap<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   370
            extraProvides.put(null, List.of());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   371
            redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   372
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   373
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   374
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   375
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   376
            List<Class<?>> containsNull = new ArrayList<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   377
            containsNull.add(null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   378
            Map<Class<?>, List<Class<?>>> extraProvides = Map.of(TestProvider.class, containsNull);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   379
            redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   380
            assertTrue(false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   381
        } catch (NullPointerException e) { }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   382
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   383
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   384
}