2.0b2 Bug leading to IllegalAccessException
"Nick Fortescue" <[email protected]> Tue, 30 Nov 2004 14:33:50 -0000
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
When calling a public method on a package scope inner class, which extends a
public superclass you get an IllegalAccessException. This is caused by one
of the top rated Sun Java bugs (
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957 ), but can be
fixed in Beanshell with a one line fix.
It appears in the current CVS version of Beanshell (2.0b2). You might want
to add your bug votes to this bug on Sun's bug DB if you have any spare.
To reproduce:
-------------
1) Compile this code
package foo;
public abstract class MyParent {
public static final MyParent INSTANCE = new MyClass();
public abstract int getValue(Number number);
private static class MyClass extends MyParent {
public int getValue(Number number) {
return 1;
}
}
}
2) Start the beanshell console.
3) Add the output from the above compilation to the classpath.
4) Type foo.MyParent.INSTANCE.getValue(new Integer(1));
To fix (one line):
---------------
Modify
if ( method != null && !Modifier.isPublic( method.getModifiers() ) )
{
try {
ReflectManager.RMSetAccessible( method );
} catch ( UtilEvalError e ) { /*ignore*/ }
}
To (you are just adding a test for a non-public class)
if ( method != null &&
(!Modifier.isPublic( method.getModifiers() ) ||
Modifier.isPublic(method.getDeclaringClass().getModifiers())) )
{
try {
ReflectManager.RMSetAccessible( method );
} catch ( UtilEvalError e ) { /*ignore*/ }
}
Nick Fortescue
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/