jdk/test/sun/reflect/ReflectionFactory/ReflectionFactoryTest.java
author chegar
Tue, 01 Nov 2016 12:37:29 +0000
changeset 41827 710feffff038
parent 41608 bb724835848f
permissions -rw-r--r--
8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor) Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     1
/*
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     4
 *
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     8
 *
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    13
 * accompanied this code).
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    14
 *
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    18
 *
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    21
 * questions.
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    22
 */
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    23
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    24
import java.io.ByteArrayInputStream;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    25
import java.io.ByteArrayOutputStream;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    26
import java.io.Externalizable;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    27
import java.io.IOException;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    28
import java.io.ObjectInput;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    29
import java.io.ObjectInputStream;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    30
import java.io.ObjectOutput;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    31
import java.io.ObjectOutputStream;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    32
import java.io.OptionalDataException;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    33
import java.io.Serializable;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    34
import java.lang.invoke.MethodHandle;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    35
import java.lang.reflect.Constructor;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    37
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    38
import sun.reflect.ReflectionFactory;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    39
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    40
import org.testng.Assert;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    41
import org.testng.annotations.BeforeClass;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    42
import org.testng.annotations.Test;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    43
import org.testng.annotations.DataProvider;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    44
import org.testng.TestNG;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    45
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    46
/*
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    47
 * @test
41827
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
    48
 * @bug 8137058 8164908 8168980
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    49
 * @run testng ReflectionFactoryTest
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    50
 * @run testng/othervm/policy=security.policy ReflectionFactoryTest
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    51
 * @summary Basic test for the unsupported ReflectionFactory
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    52
 * @modules jdk.unsupported
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    53
 */
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    54
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    55
public class ReflectionFactoryTest {
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    56
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    57
    // Initialized by init()
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    58
    static ReflectionFactory factory;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    59
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    60
    @DataProvider(name = "ClassConstructors")
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    61
    static Object[][] classConstructors() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    62
        return new Object[][] {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    63
                {Object.class},
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    64
                {Foo.class},
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    65
                {Bar.class},
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    66
        };
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    67
    }
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    68
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    69
    @BeforeClass
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    70
    static void init() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    71
        factory = ReflectionFactory.getReflectionFactory();
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    72
    }
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    73
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    74
    /**
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    75
     * Test that the correct Constructor is selected and run.
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    76
     * @param type type of object to create
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    77
     * @throws NoSuchMethodException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    78
     * @throws InstantiationException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    79
     * @throws IllegalAccessException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    80
     * @throws InvocationTargetException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    81
     */
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    82
    @Test(dataProvider="ClassConstructors")
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    83
    static void testConstructor(Class<?> type)
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    84
        throws NoSuchMethodException, InstantiationException,
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    85
            IllegalAccessException, InvocationTargetException
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    86
    {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    87
        @SuppressWarnings("unchecked")
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    88
        Constructor<?> c = factory.newConstructorForSerialization(type);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    89
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    90
        Object o = c.newInstance();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    91
        Assert.assertEquals(o.getClass(), type, "Instance is wrong type");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    92
        if (o instanceof Foo) {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    93
            Foo foo = (Foo)o;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    94
            foo.check();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
    95
        }
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    96
    }
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
    97
41827
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
    98
    @DataProvider(name = "NonSerialConstructors")
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
    99
    static Object[][] constructors() throws NoSuchMethodException {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   100
        return new Object[][] {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   101
                {Foo.class, Object.class.getDeclaredConstructor()},
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   102
                {Foo.class, Foo.class.getDeclaredConstructor()},
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   103
                {Baz.class, Object.class.getDeclaredConstructor()},
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   104
                {Baz.class, Foo.class.getDeclaredConstructor()},
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   105
                {Baz.class, Baz.class.getDeclaredConstructor()}
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   106
        };
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   107
    }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   108
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   109
    /**
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   110
     * Tests that the given Constructor, in the hierarchy, is run.
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   111
     */
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   112
    @Test(dataProvider="NonSerialConstructors")
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   113
    static void testNonSerializableConstructor(Class<?> cl,
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   114
                                               Constructor<?> constructorToCall)
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   115
        throws ReflectiveOperationException
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   116
    {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   117
        @SuppressWarnings("unchecked")
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   118
        Constructor<?> c = factory.newConstructorForSerialization(cl,
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   119
                                                                  constructorToCall);
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   120
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   121
        Object o = c.newInstance();
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   122
        Assert.assertEquals(o.getClass(), cl, "Instance is wrong type");
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   123
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   124
        int expectedFoo = 0;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   125
        int expectedBaz = 0;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   126
        if (constructorToCall.getName().equals("ReflectionFactoryTest$Foo")) {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   127
            expectedFoo = 1;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   128
        } else if (constructorToCall.getName().equals("ReflectionFactoryTest$Baz")) {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   129
            expectedFoo = 1;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   130
            expectedBaz = 4;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   131
        }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   132
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   133
        Assert.assertEquals(((Foo)o).foo(), expectedFoo);
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   134
        if (o instanceof Baz) {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   135
            Assert.assertEquals(((Baz)o).baz(), expectedBaz);
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   136
        }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   137
    }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   138
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
   139
    static class Foo {
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   140
        private int foo;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   141
        public Foo() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   142
            this.foo = 1;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   143
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   144
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   145
        public String toString() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   146
            return "foo: " + foo;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   147
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   148
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   149
        public void check() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   150
            int expectedFoo = 1;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   151
            Assert.assertEquals(foo, expectedFoo, "foo() constructor not run");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   152
        }
41827
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   153
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   154
        public int foo() { return foo; }
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   155
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   156
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   157
    static class Bar extends Foo implements Serializable {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   158
        private int bar;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   159
        public Bar() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   160
            this.bar = 1;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   161
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   162
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   163
        public String toString() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   164
            return super.toString() + ", bar: " + bar;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   165
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   166
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   167
        public void check() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   168
            super.check();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   169
            int expectedBar = 0;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   170
            Assert.assertEquals(bar, expectedBar, "bar() constructor not run");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   171
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   172
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   173
41827
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   174
    static class Baz extends Foo {
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   175
        private final int baz;
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   176
        public Baz() { this.baz = 4; }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   177
        public int baz() { return baz; }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   178
    }
710feffff038 8168980: Reinstate sun.reflect.ReflectionFactory.newConstructorForSerialization(Class,Constructor)
chegar
parents: 41608
diff changeset
   179
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   180
    /**
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   181
     * Test newConstructorForExternalization returns the constructor and it can be called.
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   182
     * @throws NoSuchMethodException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   183
     * @throws InstantiationException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   184
     * @throws IllegalAccessException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   185
     * @throws InvocationTargetException - error
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   186
     */
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   187
    @Test
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   188
    static void newConstructorForExternalization()
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   189
            throws NoSuchMethodException, InstantiationException,
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   190
            IllegalAccessException, InvocationTargetException {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   191
        Constructor<?> cons = factory.newConstructorForExternalization(Ext.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   192
        Ext ext = (Ext)cons.newInstance();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   193
        Assert.assertEquals(ext.ext, 1, "Constructor not run");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   194
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   195
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   196
    static class Ext implements Externalizable {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   197
        private static final long serialVersionUID = 1L;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   198
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   199
        int ext;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   200
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   201
        public Ext() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   202
            ext = 1;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   203
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   204
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   205
        @Override
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   206
        public void writeExternal(ObjectOutput out) throws IOException {}
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   207
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   208
        @Override
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   209
        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {}
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
   210
    }
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
   211
41608
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   212
    @Test
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   213
    static void testReadWriteObjectForSerialization() throws Throwable {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   214
        MethodHandle readObjectMethod = factory.readObjectForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   215
        Assert.assertNotNull(readObjectMethod, "readObjectMethod not found");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   216
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   217
        MethodHandle readObjectNoDataMethod = factory.readObjectNoDataForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   218
        Assert.assertNotNull(readObjectNoDataMethod, "readObjectNoDataMethod not found");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   219
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   220
        MethodHandle writeObjectMethod = factory.writeObjectForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   221
        Assert.assertNotNull(writeObjectMethod, "writeObjectMethod not found");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   222
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   223
        MethodHandle readResolveMethod = factory.readResolveForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   224
        Assert.assertNotNull(readResolveMethod, "readResolveMethod not found");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   225
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   226
        MethodHandle writeReplaceMethod = factory.writeReplaceForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   227
        Assert.assertNotNull(writeReplaceMethod, "writeReplaceMethod not found");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   228
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   229
        byte[] data = null;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   230
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   231
            ObjectOutputStream oos = new ObjectOutputStream(baos)) {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   232
            Ser ser = new Ser();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   233
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   234
            writeReplaceMethod.invoke(ser);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   235
            Assert.assertTrue(ser.writeReplaceCalled, "writeReplace not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   236
            Assert.assertFalse(ser.writeObjectCalled, "writeObject should not have been called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   237
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   238
            writeObjectMethod.invoke(ser, oos);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   239
            Assert.assertTrue(ser.writeReplaceCalled, "writeReplace should have been called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   240
            Assert.assertTrue(ser.writeObjectCalled, "writeObject not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   241
            oos.flush();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   242
            data = baos.toByteArray();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   243
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   244
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   245
        try (ByteArrayInputStream bais = new ByteArrayInputStream(data);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   246
             ObjectInputStream ois = new ObjectInputStream(bais)) {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   247
            Ser ser2 = new Ser();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   248
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   249
            readObjectMethod.invoke(ser2, ois);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   250
            Assert.assertTrue(ser2.readObjectCalled, "readObject not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   251
            Assert.assertFalse(ser2.readObjectNoDataCalled, "readObjectNoData should not be called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   252
            Assert.assertFalse(ser2.readResolveCalled, "readResolve should not be called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   253
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   254
            readObjectNoDataMethod.invoke(ser2, ois);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   255
            Assert.assertTrue(ser2.readObjectCalled, "readObject should have been called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   256
            Assert.assertTrue(ser2.readObjectNoDataCalled, "readObjectNoData not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   257
            Assert.assertFalse(ser2.readResolveCalled, "readResolve should not be called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   258
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   259
            readResolveMethod.invoke(ser2);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   260
            Assert.assertTrue(ser2.readObjectCalled, "readObject should have been called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   261
            Assert.assertTrue(ser2.readObjectNoDataCalled, "readObjectNoData not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   262
            Assert.assertTrue(ser2.readResolveCalled, "readResolve not called");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   263
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   264
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   265
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   266
    @Test
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   267
    static void hasStaticInitializer() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   268
        boolean actual = factory.hasStaticInitializerForSerialization(Ser.class);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   269
        Assert.assertTrue(actual, "hasStaticInitializerForSerialization is wrong");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   270
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   271
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   272
    static class Ser implements Serializable {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   273
        private static final long serialVersionUID = 2L;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   274
        static {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   275
            // Define a static class initialization method
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   276
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   277
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   278
        boolean readObjectCalled = false;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   279
        boolean readObjectNoDataCalled = false;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   280
        boolean writeObjectCalled = false;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   281
        boolean readResolveCalled = false;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   282
        boolean writeReplaceCalled = false;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   283
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   284
        public Ser() {}
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   285
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   286
        private void readObject(ObjectInputStream ois) throws IOException {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   287
            Assert.assertFalse(writeObjectCalled, "readObject called too many times");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   288
            readObjectCalled = ois.readBoolean();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   289
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   290
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   291
        private void readObjectNoData(ObjectInputStream ois) throws IOException {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   292
            Assert.assertFalse(readObjectNoDataCalled, "readObjectNoData called too many times");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   293
            readObjectNoDataCalled = true;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   294
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   295
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   296
        private void writeObject(ObjectOutputStream oos) throws IOException {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   297
            Assert.assertFalse(writeObjectCalled, "writeObject called too many times");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   298
            writeObjectCalled = true;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   299
            oos.writeBoolean(writeObjectCalled);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   300
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   301
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   302
        private Object writeReplace() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   303
            Assert.assertFalse(writeReplaceCalled, "writeReplace called too many times");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   304
            writeReplaceCalled = true;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   305
            return this;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   306
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   307
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   308
        private Object readResolve() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   309
            Assert.assertFalse(readResolveCalled, "readResolve called too many times");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   310
            readResolveCalled = true;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   311
            return this;
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   312
        }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   313
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   314
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   315
    /**
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   316
     * Test the constructor of OptionalDataExceptions.
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   317
     */
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   318
    @Test
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   319
    static void newOptionalDataException() {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   320
        OptionalDataException ode = factory.newOptionalDataExceptionForSerialization(true);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   321
        Assert.assertTrue(ode.eof, "eof wrong");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   322
        ode = factory.newOptionalDataExceptionForSerialization(false);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   323
        Assert.assertFalse(ode.eof, "eof wrong");
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   324
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   325
    }
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   326
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   327
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   328
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   329
    // Main can be used to run the tests from the command line with only testng.jar.
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   330
    @SuppressWarnings("raw_types")
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   331
    @Test(enabled = false)
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   332
    public static void main(String[] args) {
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   333
        Class<?>[] testclass = {ReflectionFactoryTest.class};
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   334
        TestNG testng = new TestNG();
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   335
        testng.setTestClasses(testclass);
bb724835848f 8164908: ReflectionFactory support for IIOP and custom serialization
rriggs
parents: 37363
diff changeset
   336
        testng.run();
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
   337
    }
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
diff changeset
   338
}