< prev index next >

test/hotspot/jtreg/runtime/InvocationTests/invokespecial/Checker.java

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package invokespecial;
  26 
  27 import java.lang.reflect.Method;
  28 import java.lang.reflect.Modifier;
  29 
  30 public class Checker extends shared.Checker {
  31 
  32     public Checker(Class staticTargetClass, Class dynamicTargetClass) {
  33         super(staticTargetClass, dynamicTargetClass);
  34     }
  35 
  36     public String check (Class callerClass) {
  37         /*
  38          * If objectref is null, the invokespecial instruction throws a NullPointerException.
  39          */
  40         if (dynamicTargetClass == null) {
  41             return "java.lang.NullPointerException";
  42         }
  43 
  44         /*
  45          * TODO: find a citiation from spec for this case
  46          */
  47         Method resolvedMethod;
  48         try {
  49             // May throw VerifyError
  50             resolvedMethod = getMethodInHierarchy(staticTargetClass);
  51         } catch (Throwable e) {
  52             return e.getClass().getName();
  53         }
  54 
  55         if (resolvedMethod == null) {
  56             return "java.lang.NoSuchMethodError";
  57         }
  58 
  59        /*
  60         * If:
  61         *   - the resolved method is protected (4.7)
  62         *   - it is a member of a superclass of the current class
  63         *   - the method is not declared in the same run-time package (5.3) as the current class
  64         * then:
  65         *   the class of objectref must be either the current class or a subclass of the
  66         * current class.
  67         */
  68 
  69         if (Modifier.isProtected(resolvedMethod.getModifiers())) {
  70             Method methodInSuperclass = getMethodInHierarchy(resolvedMethod.getDeclaringClass().getSuperclass());
  71 
  72             if (methodInSuperclass != null) {
  73                 String resolvedMethodPkg = getClassPackageName(resolvedMethod.getDeclaringClass());
  74                 String methodInSuperclassPkg = getClassPackageName(methodInSuperclass.getDeclaringClass());
  75 
  76                 if (!resolvedMethodPkg.equals(methodInSuperclassPkg)) {
  77                     //TODO: clarify this
  78 //                    if (callerClass == methodInSuperclass.getDeclaringClass()) {
  79 //                        return "java.lang.IllegalAccessError";
  80 //                    }
  81                 }
  82             }
  83         }
  84 
  85        /*
  86         * The resolved method is selected for invocation unless all of
  87         * the following conditions are true:




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package invokespecial;
  26 
  27 import java.lang.reflect.Method;
  28 import java.lang.reflect.Modifier;
  29 
  30 public class Checker extends shared.Checker {
  31 
  32     public Checker(Class staticTargetClass, Class dynamicTargetClass) {
  33         super(staticTargetClass, dynamicTargetClass);
  34     }
  35 
  36     public String check (Class callerClass) {
  37         // If objectref is null, the invokespecial instruction throws a NullPointerException.


  38         if (dynamicTargetClass == null) {
  39             return "java.lang.NullPointerException";
  40         }
  41 
  42         // TODO: find a citation from spec for this case


  43         Method resolvedMethod;
  44         try {
  45             // May throw VerifyError
  46             resolvedMethod = getMethodInHierarchy(staticTargetClass);
  47         } catch (Throwable e) {
  48             return e.getClass().getName();
  49         }
  50 
  51         if (resolvedMethod == null) {
  52             return "java.lang.NoSuchMethodError";
  53         }
  54 
  55        // If:
  56        //   - the resolved method is protected (4.7)
  57        //   - it is a member of a superclass of the current class
  58        //   - the method is not declared in the same run-time package (5.3) as the current class
  59        // then:
  60        //   the class of objectref must be either the current class or a subclass of the
  61        // current class.


  62 
  63         if (Modifier.isProtected(resolvedMethod.getModifiers())) {
  64             Method methodInSuperclass = getMethodInHierarchy(resolvedMethod.getDeclaringClass().getSuperclass());
  65 
  66             if (methodInSuperclass != null) {
  67                 String resolvedMethodPkg = getClassPackageName(resolvedMethod.getDeclaringClass());
  68                 String methodInSuperclassPkg = getClassPackageName(methodInSuperclass.getDeclaringClass());
  69 
  70                 if (!resolvedMethodPkg.equals(methodInSuperclassPkg)) {
  71                     //TODO: clarify this
  72 //                    if (callerClass == methodInSuperclass.getDeclaringClass()) {
  73 //                        return "java.lang.IllegalAccessError";
  74 //                    }
  75                 }
  76             }
  77         }
  78 
  79        /*
  80         * The resolved method is selected for invocation unless all of
  81         * the following conditions are true:


< prev index next >