jdk/test/java/rmi/server/getRemoteClass/GetRemoteClass.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14778 5947768d173d
child 30820 0d4717a011d3
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14778
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4152295
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary trivial optimization in RemoteProxy.extendsRemote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Laird Dornin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @library ../../testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    31
 * @build TestLibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main/othervm GetRemoteClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.rmi.server.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Simple test to make sure that Util.getRemoteClass throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * exception in proper circumstances.  Pass two different classes, one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * that extends Remote and one that only extends Serializable.  Should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * throw exception for Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class GetRemoteClass {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public interface ExtendRemote extends Remote {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static class TestRemote implements ExtendRemote {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static class OnlySerializable implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static void main(String[] argv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.err.println("\nregression test for 4152295\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Method utilGetRemoteClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
             * Use reflection to set access overrides so that the test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
             * can call protected method, getRemoteClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Class[] args = new Class[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            args[0] = Class.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            utilGetRemoteClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                Util.class.getDeclaredMethod("getRemoteClass", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            utilGetRemoteClass.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            // getRemoteClass can be invoked without exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            utilGetRemoteClass.invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                 (null , new Object [] {TestRemote.class});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            System.err.println("remote class flagged as remote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            ClassNotFoundException cnfe = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                // getRemoteClass can be invoked without exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                utilGetRemoteClass.invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    (null , new Object [] {OnlySerializable.class});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                System.err.println("got ClassNotFoundException; remote " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                   "class flagged as nonremote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                cnfe = (ClassNotFoundException) e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (cnfe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                TestLibrary.bomb("Serializable class flagged as remote?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.err.println("Test passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            TestLibrary.bomb("Unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}