test/jdk/javax/swing/UIDefaults/8080972/TestProxyLazyValue.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
import javax.swing.SwingUtilities;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import javax.swing.UIDefaults;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @bug 8080972
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @summary Audit Core Reflection in module java.desktop for places that will
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *          require changes to work with modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @author Alexander Scherbatiy
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    31
 * @run main/othervm TestProxyLazyValue
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
public class TestProxyLazyValue {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
        SwingUtilities.invokeAndWait(TestProxyLazyValue::testUserProxyLazyValue);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
        SwingUtilities.invokeAndWait(TestProxyLazyValue::testProxyLazyValue);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
        System.setSecurityManager(new SecurityManager());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
        SwingUtilities.invokeAndWait(TestProxyLazyValue::testUserProxyLazyValue);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
        SwingUtilities.invokeAndWait(TestProxyLazyValue::testProxyLazyValue);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    private static void testUserProxyLazyValue() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        Object obj = new UserProxyLazyValue(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
                UserLazyClass.class.getName()).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        if (!(obj instanceof UserLazyClass)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
            throw new RuntimeException("Object is not UserLazyClass!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        obj = new UserProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                new Object[]{UserLazyClass.CONSTRUCTOR_ARG}).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        if (!(obj instanceof UserLazyClass)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
            throw new RuntimeException("Object is not UserLazyClass!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        if (((UserLazyClass) obj).arg != UserLazyClass.CONSTRUCTOR_ARG) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            throw new RuntimeException("Constructt argument is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        obj = new UserProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                "method1").createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        if (!UserLazyClass.RESULT_1.equals(obj)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            throw new RuntimeException("Result is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        obj = new UserProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                "method2", new Object[]{UserLazyClass.RESULT_2}).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        if (!UserLazyClass.RESULT_2.equals(obj)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            throw new RuntimeException("Result is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    private static void testProxyLazyValue() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Object obj = new UIDefaults.ProxyLazyValue(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                UserLazyClass.class.getName()).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        if (!(obj instanceof UserLazyClass)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            throw new RuntimeException("Object is not UserLazyClass!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                new Object[]{UserLazyClass.CONSTRUCTOR_ARG}).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        if (!(obj instanceof UserLazyClass)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            throw new RuntimeException("Object is not UserLazyClass!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        if (((UserLazyClass) obj).arg != UserLazyClass.CONSTRUCTOR_ARG) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            throw new RuntimeException("Constructt argument is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                "method1").createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        if (!UserLazyClass.RESULT_1.equals(obj)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            throw new RuntimeException("Result is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        obj = new UIDefaults.ProxyLazyValue(UserLazyClass.class.getName(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                "method2", new Object[]{UserLazyClass.RESULT_2}).createValue(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        if (!UserLazyClass.RESULT_2.equals(obj)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            throw new RuntimeException("Result is wrong!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    public static class UserLazyClass {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        static final int CONSTRUCTOR_ARG = 100;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        static final String RESULT_1 = "1";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        static final String RESULT_2 = "2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        int arg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        public UserLazyClass() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        public UserLazyClass(int arg) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            this.arg = arg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        public static String method1() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            return RESULT_1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        public static String method2(String arg) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            return arg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    public static class UserProxyLazyValue extends UIDefaults.ProxyLazyValue {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        public UserProxyLazyValue(String className) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            super(className);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        public UserProxyLazyValue(String className, Object[] constructorArgs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            super(className, constructorArgs);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        public UserProxyLazyValue(String className, String methodName) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            super(className, methodName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        public UserProxyLazyValue(String className, String methodName,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                Object[] methodArgs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            super(className, methodName, methodArgs);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
}