test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java
author mchung
Tue, 13 Aug 2019 15:49:11 -0700
changeset 57735 7ba5e49258de
permissions -rw-r--r--
8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works 8209078: Unable to call default method from interface in another module from named module Reviewed-by: dfuchs, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57735
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     1
/*
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     4
 *
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     8
 *
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    13
 * accompanied this code).
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    14
 *
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    18
 *
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    21
 * questions.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    22
 */
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    23
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    24
/**
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    25
 * @test
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    26
 * @bug 8209005 8209078
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    27
 * @library /test/lib
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    28
 * @build m1/* FindSpecialTest
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    29
 * @run testng/othervm FindSpecialTest
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    30
 * @summary Test findSpecial and unreflectSpecial of the declaring class
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    31
 *          of the method and the special caller are not in the same module
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    32
 *          as the lookup class.
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    33
 */
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    34
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    35
import java.io.File;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    36
import java.nio.file.Files;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    37
import java.nio.file.Path;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    38
import java.nio.file.Paths;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    39
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    40
import jdk.test.lib.JDKToolFinder;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    41
import jdk.test.lib.process.ProcessTools;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    42
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    43
import org.testng.annotations.Test;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    44
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    45
public class FindSpecialTest {
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    46
    static final String JAVA_LAUNCHER = JDKToolFinder.getJDKTool("java");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    47
    static final String TEST_CLASSES = System.getProperty("test.classes", ".");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    48
    static final String TEST_CLASS_PATH = System.getProperty("test.class.path");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    49
    static final String TEST_MAIN_CLASS = "test.FindSpecial";
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    50
    static final String TEST_MODULE = "m1";
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    51
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    52
    /*
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    53
     * Run test.FindSpecial in unnamed module
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    54
     */
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    55
    @Test
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    56
    public static void callerInUnnamedModule() throws Throwable {
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    57
        Path m1 = Paths.get(TEST_CLASSES, "modules", TEST_MODULE);
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    58
        if (Files.notExists(m1)) {
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    59
            throw new Error(m1 + " not exist");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    60
        }
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    61
        String classpath = m1.toString() + File.pathSeparator + TEST_CLASS_PATH;
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    62
        ProcessTools.executeCommand(JAVA_LAUNCHER, "-cp", classpath, TEST_MAIN_CLASS)
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    63
                    .shouldHaveExitValue(0);
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    64
    }
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    65
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    66
    /*
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    67
     * Run test.FindSpecial in a named module
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    68
     */
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    69
    @Test
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    70
    public static void callerInNamedModule() throws Throwable {
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    71
        Path modules = Paths.get(TEST_CLASSES, "modules");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    72
        if (Files.notExists(modules)) {
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    73
            throw new Error(modules + " not exist");
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    74
        }
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    75
        ProcessTools.executeCommand(JAVA_LAUNCHER,
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    76
                                    "-cp", TEST_CLASS_PATH,
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    77
                                    "-p", modules.toString(),
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    78
                                    "-m", TEST_MODULE + "/" + TEST_MAIN_CLASS)
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    79
                    .shouldHaveExitValue(0);
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    80
    }
7ba5e49258de 8209005: Lookup.unreflectSpecial fails for default methods when Lookup.findSpecial works
mchung
parents:
diff changeset
    81
}