jdk/test/tools/launcher/modules/permit/PermitIllegalAccess.java
author alanb
Fri, 24 Mar 2017 16:35:51 +0000
changeset 44364 9cc9dc782213
parent 44359 c6761862ca0b
permissions -rw-r--r--
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens Reviewed-by: chegar, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     1
/*
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     4
 *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     8
 *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    13
 * accompanied this code).
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    14
 *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    18
 *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    21
 * questions.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    22
 */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    23
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    24
/**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    25
 * @test
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    26
 * @library /lib/testlibrary
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    27
 * @build PermitIllegalAccess AttemptAccess jdk.testlibrary.*
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    28
 * @run testng PermitIllegalAccess
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    29
 * @summary Basic test for java --permit-illegal-access
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    30
 */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    31
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    32
import java.util.ArrayList;
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    33
import java.util.Arrays;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    34
import java.util.List;
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    35
import java.util.stream.Stream;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    36
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    37
import jdk.testlibrary.ProcessTools;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    38
import jdk.testlibrary.OutputAnalyzer;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    39
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    40
import org.testng.annotations.Test;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    41
import static org.testng.Assert.*;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    42
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    43
/**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    44
 * Basic test of --permit-illegal-access to ensure that it permits access
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    45
 * via core reflection and setAccessible/trySetAccessible.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    46
 */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    47
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    48
@Test
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    49
public class PermitIllegalAccess {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    50
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    51
    static final String TEST_CLASSES = System.getProperty("test.classes");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    52
    static final String TEST_MAIN = "AttemptAccess";
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    53
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    54
    static final String WARNING = "WARNING";
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    55
    static final String STARTUP_WARNING =
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    56
        "WARNING: --permit-illegal-access will be removed in the next major release";
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    57
    static final String ILLEGAL_ACCESS_WARNING =
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    58
        "WARNING: Illegal access by " + TEST_MAIN;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    59
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    60
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    61
     * Launches AttemptAccess to execute an action, returning the OutputAnalyzer
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    62
     * to analyze the output/exitCode.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    63
     */
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    64
    private OutputAnalyzer tryAction(String action, int count, String... args)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    65
        throws Exception
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    66
    {
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    67
        Stream<String> s1 = Stream.of(args);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    68
        Stream<String> s2 = Stream.of("-cp", TEST_CLASSES, TEST_MAIN, action, "" + count);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    69
        String[] opts = Stream.concat(s1, s2).toArray(String[]::new);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    70
        return ProcessTools.executeTestJava(opts)
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    71
                .outputTo(System.out)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    72
                .errorTo(System.out);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    73
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    74
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    75
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    76
     * Launches AttemptAccess with --permit-illegal-access to execute an action,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    77
     * returning the OutputAnalyzer to analyze the output/exitCode.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    78
     */
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    79
    private OutputAnalyzer tryActionPermittingIllegalAccess(String action, int count)
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    80
        throws Exception
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    81
    {
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
    82
        return tryAction(action, count, "--permit-illegal-access");
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    83
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    84
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    85
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    86
     * Sanity check to ensure that IllegalAccessException is thrown.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    87
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    88
    public void testAccessFail() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    89
        int exitValue = tryAction("access", 1)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    90
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    91
                .stdoutShouldNotContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    92
                .stderrShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    93
                .stderrShouldContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    94
                .getExitValue();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    95
        assertTrue(exitValue != 0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    96
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    97
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    98
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
    99
     * Sanity check to ensure that InaccessibleObjectException is thrown.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   100
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   101
    public void testSetAccessibleFail() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   102
        int exitValue = tryAction("setAccessible", 1)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   103
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   104
                .stdoutShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   105
                .stderrShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   106
                .stderrShouldContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   107
                .getExitValue();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   108
        assertTrue(exitValue != 0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   109
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   110
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   111
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   112
     * Permit illegal access to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   113
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   114
    public void testAccessPermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   115
        tryActionPermittingIllegalAccess("access", 1)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   116
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   117
                .stdoutShouldNotContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   118
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   119
                .stderrShouldNotContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   120
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   121
                .shouldHaveExitValue(0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   122
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   123
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   124
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   125
     * Permit repeated illegal access to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   126
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   127
    public void testRepeatedAccessPermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   128
        OutputAnalyzer outputAnalyzer = tryActionPermittingIllegalAccess("access", 10)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   129
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   130
                .stdoutShouldNotContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   131
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   132
                .stderrShouldNotContain("IllegalAccessException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   133
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   134
                .shouldHaveExitValue(0);;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   135
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   136
        // should only have one illegal access warning
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   137
        assertTrue(containsCount(outputAnalyzer.asLines(), ILLEGAL_ACCESS_WARNING) == 1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   138
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   139
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   140
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   141
     * Permit setAccessible to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   142
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   143
    public void testSetAccessiblePermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   144
        tryActionPermittingIllegalAccess("setAccessible", 1)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   145
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   146
                .stdoutShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   147
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   148
                .stderrShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   149
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   150
                .shouldHaveExitValue(0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   151
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   152
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   153
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   154
     * Permit repeated calls to setAccessible to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   155
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   156
    public void testRepeatedSetAccessiblePermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   157
        OutputAnalyzer outputAnalyzer = tryActionPermittingIllegalAccess("setAccessible", 10)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   158
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   159
                .stdoutShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   160
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   161
                .stderrShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   162
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   163
                .shouldHaveExitValue(0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   164
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   165
        // should only have one illegal access warning
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   166
        assertTrue(containsCount(outputAnalyzer.asLines(), ILLEGAL_ACCESS_WARNING) == 1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   167
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   168
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   169
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   170
     * Permit trySetAccessible to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   171
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   172
    public void testTrySetAccessiblePermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   173
        tryActionPermittingIllegalAccess("trySetAccessible", 1)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   174
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   175
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   176
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   177
                .shouldHaveExitValue(0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   178
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   179
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   180
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   181
     * Permit repeated calls to trySetAccessible to succeed
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   182
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   183
    public void testRepeatedTrySetAccessiblePermitted() throws Exception {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   184
        OutputAnalyzer outputAnalyzer = tryActionPermittingIllegalAccess("trySetAccessible", 10)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   185
                .stdoutShouldNotContain(WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   186
                .stdoutShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   187
                .stderrShouldContain(STARTUP_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   188
                .stderrShouldNotContain("InaccessibleObjectException")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   189
                .stderrShouldContain(ILLEGAL_ACCESS_WARNING)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   190
                .shouldHaveExitValue(0);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   191
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   192
        // should only have one illegal access warning
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   193
        assertTrue(containsCount(outputAnalyzer.asLines(), ILLEGAL_ACCESS_WARNING) == 1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   194
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   195
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   196
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   197
    /**
44364
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   198
     * Permit access to succeed with --add-exports. No warning should be printed.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   199
     */
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   200
    public void testAccessWithAddExports() throws Exception {
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   201
        tryAction("access", 1, "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   202
                .stdoutShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   203
                .stdoutShouldNotContain("IllegalAccessException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   204
                .stderrShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   205
                .stderrShouldNotContain("IllegalAccessException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   206
                .shouldHaveExitValue(0);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   207
    }
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   208
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   209
    /**
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   210
     * Permit access to succeed with --add-exports and --permit-illegal-access.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   211
     * The only warning emitted should be the startup warning.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   212
     */
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   213
    public void testAccessWithePermittedAddExports() throws Exception {
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   214
        tryAction("access", 1, "--permit-illegal-access",
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   215
                    "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   216
                .stdoutShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   217
                .stdoutShouldNotContain("IllegalAccessException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   218
                .stderrShouldContain(STARTUP_WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   219
                .stderrShouldNotContain("IllegalAccessException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   220
                .stderrShouldNotContain(ILLEGAL_ACCESS_WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   221
                .shouldHaveExitValue(0);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   222
    }
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   223
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   224
    /**
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   225
     * Permit setAccessible to succeed with --add-opens. No warning should be printed.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   226
     */
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   227
    public void testSetAccessibleWithAddOpens() throws Exception {
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   228
        tryAction("setAccessible", 1, "--add-opens", "java.base/java.lang=ALL-UNNAMED")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   229
                .stdoutShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   230
                .stdoutShouldNotContain("InaccessibleObjectException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   231
                .stderrShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   232
                .stderrShouldNotContain("InaccessibleObjectException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   233
                .shouldHaveExitValue(0);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   234
    }
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   235
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   236
    /**
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   237
     * Permit setAccessible to succeed with both --add-opens and --permit-illegal-access.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   238
     * The only warning emitted should be the startup warning.
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   239
     */
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   240
    public void testSetAccessiblePermittedWithAddOpens() throws Exception {
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   241
        tryAction("setAccessible", 1, "--permit-illegal-access",
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   242
                    "--add-opens", "java.base/java.lang=ALL-UNNAMED")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   243
                .stdoutShouldNotContain(WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   244
                .stdoutShouldNotContain("InaccessibleObjectException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   245
                .stderrShouldContain(STARTUP_WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   246
                .stderrShouldNotContain("InaccessibleObjectException")
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   247
                .stderrShouldNotContain(ILLEGAL_ACCESS_WARNING)
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   248
                .shouldHaveExitValue(0);
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   249
    }
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   250
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   251
9cc9dc782213 8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents: 44359
diff changeset
   252
    /**
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   253
     * Returns the number of lines in the given input that contain the
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   254
     * given char sequence.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   255
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   256
    private int containsCount(List<String> lines, CharSequence cs) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   257
        int count = 0;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   258
        for (String line : lines) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   259
            if (line.contains(cs)) count++;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   260
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   261
        return count;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   262
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents:
diff changeset
   263
}