HEAD regression: no more access to public members of package private classes

VERIFIED FIXED in 1.5R5

Status

VERIFIED FIXED
16 years ago
15 years ago

People

(Reporter: igor, Assigned: norrisboyd)

Tracking

other
1.5R5

Details

Attachments

(2 attachments)

(Reporter)

Description

16 years ago
A work related to bug 201893 made the following regression as reported by Hannes
Wallnoefer in the comments at bug 201893#c6 :


I think there are some problems with the patch you committed. I'm no longer able
to invoke public methods on non-public classes. The error message I get is:

TypeError: undefined is not a function.

Which may serve as clue, because it's not that we get a security exception when
invoking the method, the method is simply not there.

Also, when trying to invoke a public static method on a non-public class, I get
the following message:

org.mozilla.javascript.EvaluatorException: Java class "java.lang.Object" has no
public instance field or method named "foo".
(Reporter)

Comment 1

16 years ago
CC to Hannes Wallnoefer
OS: Linux → All
Hardware: PC → All
(Reporter)

Comment 2

16 years ago
Created attachment 128945 [details]
Java test case to check reflection support

To test, compile X.java, make all the resulting classes available to JVM and
run the following Java scripts in Rhino shell:

print(Packages.X.test().str())
print(Packages.X.test().str2())

Currenly only the first line works properly and prints TEST but the second line
gives instead of printing TEST2:

uncaught JavaScript exception: TypeError: str2 is not a function.

Note that the second line is supposed to work only if SecurityManager allows to
access public methods of package-private classes, but even in that situation
the error should be about IllegalAccessException, not about non-existing
function.
(Reporter)

Comment 3

16 years ago
Created attachment 128947 [details] [diff] [review]
Fix: allow to reflect package-private classes in JavaMembers.lookupClass

The reason for the regression is that now JavaMembers.lookupClass never
attempts to reflect package-private classes. But this is wrong since even with
SecirutyManager installed JVM allows to call Class.getMethos()( and returns
list of all public methods in the class and its super classes.

The patch removes the restrictions while making JavaMembers.lookupClass much
simpler.

Comment 4

16 years ago
Yep, patch works well for me!
(Reporter)

Comment 5

16 years ago
I committed the patch.
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → FIXED
(Reporter)

Comment 6

16 years ago
Now with the patch committed Rhino shell prints TEST2 for
print(Packages.X.test().str2()) if access permissions allows access to public
methods of package-private classes and when not it prints:

js: "<command>", line 1: While attempting to call "str2" in class "MyTest"
receieved java.lang.IllegalAccessException

which is expected.

Comment 7

16 years ago
Marking Verified per Comment #4
Status: RESOLVED → VERIFIED
(Reporter)

Comment 8

15 years ago
Targeting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.