8062050: A method is considered caller sensitive, but it doesn't have the CallerSensitive annotation

Mon, 03 Nov 2014 07:29:46 +0100

author
attila
date
Mon, 03 Nov 2014 07:29:46 +0100
changeset 1081
a54684572f14
parent 1080
ad5f0c0eb313
child 1082
e1e27c4262be

8062050: A method is considered caller sensitive, but it doesn't have the CallerSensitive annotation
Reviewed-by: hannesw, lagergren

src/jdk/internal/dynalink/beans/AbstractJavaLinker.java file | annotate | diff | comparison | revisions
test/src/jdk/internal/dynalink/beans/CallerSensitiveTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/test/models/ClassLoaderAware.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Mon Nov 03 07:28:08 2014 +0100
     1.2 +++ b/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Mon Nov 03 07:29:46 2014 +0100
     1.3 @@ -287,10 +287,21 @@
     1.4       */
     1.5      private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
     1.6          if(CallerSensitiveDetector.isCallerSensitive(m)) {
     1.7 +            // Method has @CallerSensitive annotation
     1.8              return new CallerSensitiveDynamicMethod(m);
     1.9          }
    1.10 +        // Method has no @CallerSensitive annotation
    1.11 +        final MethodHandle mh;
    1.12 +        try {
    1.13 +            mh = unreflectSafely(m);
    1.14 +        } catch (final IllegalAccessError e) {
    1.15 +            // java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
    1.16 +            // marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
    1.17 +            return new CallerSensitiveDynamicMethod(m);
    1.18 +        }
    1.19 +        // Proceed with non-caller sensitive
    1.20          final Member member = (Member)m;
    1.21 -        return new SimpleDynamicMethod(unreflectSafely(m), member.getDeclaringClass(), member.getName(), m instanceof Constructor);
    1.22 +        return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
    1.23      }
    1.24  
    1.25      /**
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/jdk/internal/dynalink/beans/CallerSensitiveTest.java	Mon Nov 03 07:29:46 2014 +0100
     2.3 @@ -0,0 +1,36 @@
     2.4 +/*
     2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +package jdk.internal.dynalink.beans;
    2.30 +
    2.31 +import jdk.nashorn.test.models.ClassLoaderAware;
    2.32 +import org.testng.annotations.Test;
    2.33 +
    2.34 +public class CallerSensitiveTest {
    2.35 +    @Test
    2.36 +    public void testCallerSensitive() {
    2.37 +        BeansLinker.getLinkerForClass(ClassLoaderAware.class);
    2.38 +    }
    2.39 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/src/jdk/nashorn/test/models/ClassLoaderAware.java	Mon Nov 03 07:29:46 2014 +0100
     3.3 @@ -0,0 +1,31 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Oracle designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Oracle in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.25 + * or visit www.oracle.com if you need additional information or have any
    3.26 + * questions.
    3.27 + */
    3.28 +
    3.29 +package jdk.nashorn.test.models;
    3.30 +
    3.31 +public interface ClassLoaderAware {
    3.32 +    public ClassLoader getContextClassLoader();
    3.33 +    public void checkMemberAccess(Class<?> clazz, int which);
    3.34 +}

mercurial