Fix problem found by Andrew Wason <aw@softcom.com>:

Subject:
        reflection and illegal package access
   Date:
        Wed, 04 Aug 1999 21:56:20 -0400
   From:
        Andrew Wason <aw@softcom.com>
     To:
        norris@netscape.com (Norris Boyd)
    CC:
        Howard Lin <howard@softcom.com>




If you run Rhino under JDK1.2 with a security manager:

java -Djava.security.manager=java.lang.SecurityManager
org.mozilla.javascript.tools.shell.Main

Then reflection fails for objects that are in a restricted access package
(e.g. sun.*).  Rhino is reflecting based on the dynamic type of the object
instead of the declared static return type.

In this example, createImage is declared to return java.awt.Image, but it
returns sun.awt.image.OffScreenImage.  Attempting to reflect this class
results in a java.security.AccessControlException for
java.lang.RuntimePermission accessClassInPackage.sun.awt.image.

Here is the script.  You will need to type it in because you won't be able
to load it from a file due to the security manager.

var f = new java.awt.Frame();
f.setVisible(true);
var i = f.createImage(10,10);
This commit is contained in:
norris%netscape.com 1999-08-05 16:49:20 +00:00
parent 641c591fae
commit d055865e6d
2 changed files with 24 additions and 2 deletions

View File

@ -328,7 +328,18 @@ class JavaMembers {
members = (JavaMembers) classTable.get(cl);
if (members != null)
return members;
members = new JavaMembers(scope, cl);
try {
members = new JavaMembers(scope, cl);
} catch (SecurityException e) {
// Reflection may fail for objects that are in a restricted
// access package (e.g. sun.*). If we get a security
// exception, try again with the static type. Otherwise,
// rethrow the exception.
if (cl != staticType)
members = new JavaMembers(scope, staticType);
else
throw e;
}
classTable.put(cl, members);
return members;
}

View File

@ -328,7 +328,18 @@ class JavaMembers {
members = (JavaMembers) classTable.get(cl);
if (members != null)
return members;
members = new JavaMembers(scope, cl);
try {
members = new JavaMembers(scope, cl);
} catch (SecurityException e) {
// Reflection may fail for objects that are in a restricted
// access package (e.g. sun.*). If we get a security
// exception, try again with the static type. Otherwise,
// rethrow the exception.
if (cl != staticType)
members = new JavaMembers(scope, staticType);
else
throw e;
}
classTable.put(cl, members);
return members;
}