# HG changeset patch # User sundar # Date 1391088840 -19800 # Node ID eca774d33fa4940a1d6f7ae1f1445d5f783ab669 # Parent a43c125b03dc77906749ed2a178cac7651e733cd 8032954: Nashorn: extend Java.extend Reviewed-by: attila, jlaskey, ahgross diff -r a43c125b03dc -r eca774d33fa4 src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Thu Jan 30 18:34:37 2014 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Thu Jan 30 19:04:00 2014 +0530 @@ -110,6 +110,8 @@ for (Class type : types) { // check for restricted package access Context.checkPackageAccess(type); + // check for classes, interfaces in reflection + ReflectionCheckLinker.checkReflectionAccess(type); } } return getAdapterInfo(types).getAdapterClassFor(classOverrides); diff -r a43c125b03dc -r eca774d33fa4 test/script/sandbox/classbind.js --- a/test/script/sandbox/classbind.js Thu Jan 30 18:34:37 2014 +0530 +++ b/test/script/sandbox/classbind.js Thu Jan 30 19:04:00 2014 +0530 @@ -25,7 +25,7 @@ * Try to bind properties of StaticClass representing Class. * * @test - * @security + * @bug JDK-8032943: Improve reflection in Nashorn */ diff -r a43c125b03dc -r eca774d33fa4 test/script/sandbox/classloader.js --- a/test/script/sandbox/classloader.js Thu Jan 30 18:34:37 2014 +0530 +++ b/test/script/sandbox/classloader.js Thu Jan 30 19:04:00 2014 +0530 @@ -26,6 +26,7 @@ * * @test * @security + * @bug JDK-8032954: Nashorn: extend Java.extend */ try { @@ -39,3 +40,24 @@ } } +try { + Java.extend(Java.type('java.lang.ClassLoader')); + fail("should have thrown SecurityException"); +} catch (e) { + if (e instanceof java.lang.SecurityException) { + print(e); + } else { + fail("expected SecurityException, got " + e); + } +} + +try { + Java.extend(Java.type("javax.management.loading.MLet")); + fail("should have thrown SecurityException"); +} catch (e) { + if (e instanceof java.lang.SecurityException) { + print(e); + } else { + fail("expected SecurityException, got " + e); + } +} diff -r a43c125b03dc -r eca774d33fa4 test/script/sandbox/classloader.js.EXPECTED --- a/test/script/sandbox/classloader.js.EXPECTED Thu Jan 30 18:34:37 2014 +0530 +++ b/test/script/sandbox/classloader.js.EXPECTED Thu Jan 30 19:04:00 2014 +0530 @@ -1,1 +1,3 @@ java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") +java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") +java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection")