< prev index next >

modules/javafx.base/src/main/java/com/sun/javafx/reflect/MethodUtil.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  26 package com.sun.javafx.reflect;
  27 
  28 import java.io.EOFException;
  29 import java.security.AllPermission;
  30 import java.security.AccessController;
  31 import java.security.PermissionCollection;
  32 import java.security.SecureClassLoader;
  33 import java.security.PrivilegedExceptionAction;
  34 import java.security.CodeSource;
  35 import java.io.InputStream;
  36 import java.io.BufferedInputStream;
  37 import java.io.IOException;
  38 import java.net.URL;
  39 import java.net.URLConnection;
  40 import java.lang.reflect.Method;
  41 import java.lang.reflect.InvocationTargetException;
  42 import java.lang.reflect.Modifier;
  43 import java.util.Arrays;
  44 import java.util.HashMap;
  45 import java.util.Map;
  46 import sun.reflect.misc.ReflectUtil;
  47 
  48 
  49 class Trampoline {
  50     static {
  51         if (Trampoline.class.getClassLoader() == null) {
  52             throw new Error(
  53                 "Trampoline must not be defined by the bootstrap classloader");
  54         }
  55         if (Trampoline.class.getClassLoader() == ClassLoader.getPlatformClassLoader()) {
  56             throw new Error(
  57                 "Trampoline must not be defined by the platform classloader");
  58         }
  59     }
  60 
  61     private static void ensureInvocableMethod(Method m)
  62         throws InvocationTargetException
  63     {
  64         Class<?> clazz = m.getDeclaringClass();
  65         if (clazz.equals(AccessController.class) ||
  66             clazz.equals(Method.class) ||


  72     private static Object invoke(Method m, Object obj, Object[] params)
  73         throws InvocationTargetException, IllegalAccessException
  74     {
  75         ensureInvocableMethod(m);
  76         return m.invoke(obj, params);
  77     }
  78 }
  79 
  80 /*
  81  * Create a trampoline class.
  82  */
  83 public final class MethodUtil extends SecureClassLoader {
  84     private static final String MISC_PKG = "com.sun.javafx.reflect.";
  85     private static final String TRAMPOLINE = MISC_PKG + "Trampoline";
  86     private static final Method bounce = getTrampoline();
  87 
  88     private MethodUtil() {
  89         super();
  90     }
  91 
  92     /*public*/
  93     static Method getMethod(Class<?> cls, String name, Class<?>[] args)
  94         throws NoSuchMethodException {
  95         ReflectUtil.checkPackageAccess(cls);
  96         return cls.getMethod(name, args);
  97     }
  98 
  99     /*public*/
 100     static Method[] getMethods(Class<?> cls) {
 101         ReflectUtil.checkPackageAccess(cls);
 102         return cls.getMethods();
 103     }
 104 
 105     /*
 106      * Discover the public methods on public classes
 107      * and interfaces accessible to any caller by calling
 108      * Class.getMethods() and walking towards Object until
 109      * we're done.
 110      */
 111     /*public*/
 112     static Method[] getPublicMethods(Class<?> cls) {
 113         // compatibility for update release
 114         if (System.getSecurityManager() == null) {
 115             return cls.getMethods();
 116         }
 117         Map<Signature, Method> sigs = new HashMap<Signature, Method>();
 118         while (cls != null) {
 119             boolean done = getInternalPublicMethods(cls, sigs);
 120             if (done) {


   1 /*
   2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  26 package com.sun.javafx.reflect;
  27 
  28 import java.io.EOFException;
  29 import java.security.AllPermission;
  30 import java.security.AccessController;
  31 import java.security.PermissionCollection;
  32 import java.security.SecureClassLoader;
  33 import java.security.PrivilegedExceptionAction;
  34 import java.security.CodeSource;
  35 import java.io.InputStream;
  36 import java.io.BufferedInputStream;
  37 import java.io.IOException;
  38 import java.net.URL;
  39 import java.net.URLConnection;
  40 import java.lang.reflect.Method;
  41 import java.lang.reflect.InvocationTargetException;
  42 import java.lang.reflect.Modifier;
  43 import java.util.Arrays;
  44 import java.util.HashMap;
  45 import java.util.Map;
  46 import com.sun.javafx.reflect.ReflectUtil;
  47 
  48 
  49 class Trampoline {
  50     static {
  51         if (Trampoline.class.getClassLoader() == null) {
  52             throw new Error(
  53                 "Trampoline must not be defined by the bootstrap classloader");
  54         }
  55         if (Trampoline.class.getClassLoader() == ClassLoader.getPlatformClassLoader()) {
  56             throw new Error(
  57                 "Trampoline must not be defined by the platform classloader");
  58         }
  59     }
  60 
  61     private static void ensureInvocableMethod(Method m)
  62         throws InvocationTargetException
  63     {
  64         Class<?> clazz = m.getDeclaringClass();
  65         if (clazz.equals(AccessController.class) ||
  66             clazz.equals(Method.class) ||


  72     private static Object invoke(Method m, Object obj, Object[] params)
  73         throws InvocationTargetException, IllegalAccessException
  74     {
  75         ensureInvocableMethod(m);
  76         return m.invoke(obj, params);
  77     }
  78 }
  79 
  80 /*
  81  * Create a trampoline class.
  82  */
  83 public final class MethodUtil extends SecureClassLoader {
  84     private static final String MISC_PKG = "com.sun.javafx.reflect.";
  85     private static final String TRAMPOLINE = MISC_PKG + "Trampoline";
  86     private static final Method bounce = getTrampoline();
  87 
  88     private MethodUtil() {
  89         super();
  90     }
  91 
  92     public static Method getMethod(Class<?> cls, String name, Class<?>[] args)

  93         throws NoSuchMethodException {
  94         ReflectUtil.checkPackageAccess(cls);
  95         return cls.getMethod(name, args);
  96     }
  97 
  98     public static Method[] getMethods(Class<?> cls) {

  99         ReflectUtil.checkPackageAccess(cls);
 100         return cls.getMethods();
 101     }
 102 
 103     /*
 104      * Discover the public methods on public classes
 105      * and interfaces accessible to any caller by calling
 106      * Class.getMethods() and walking towards Object until
 107      * we're done.
 108      */
 109     /*public*/
 110     static Method[] getPublicMethods(Class<?> cls) {
 111         // compatibility for update release
 112         if (System.getSecurityManager() == null) {
 113             return cls.getMethods();
 114         }
 115         Map<Signature, Method> sigs = new HashMap<Signature, Method>();
 116         while (cls != null) {
 117             boolean done = getInternalPublicMethods(cls, sigs);
 118             if (done) {


< prev index next >