-
Enhancement
-
Resolution: Duplicate
-
P3
-
None
-
1.1
-
x86
-
windows_95
Name: mc57594 Date: 05/21/97
Create the two files listed below (Bug.java and pkg\Foo.java). Compile them using javac. Run "java Bug". You will get an illegal access exception. It does not matter if getFoo() is static or not.
This is a very serious bug in that invoking accessor methods on Java Beans properties in a generic fashion is hampered by this.
A sample run of the program prints :
D:\java_bugs\three>java Bug
Method = public int pkg.Bar.getFoo()
Exception caught:java.lang.IllegalAccessException: pkg/Bar
FILE1: Bug.java
import java.lang.reflect.*;
import pkg.*;
public class Bug
{
public static void main(String[] args)
{
try
{
Class cls = pkg.Foo.class;
Method method = cls.getMethod("getFoo", null);
System.out.println("Method = " + method );
Foo foo = new Foo();
method.invoke( foo, null );
}
catch (Exception e)
{
System.out.println("Exception caught:" + e.toString() );
}
}
}
FILE2: pkg\Foo.java
package pkg;
class Bar
{
public int getFoo() { return 1; }
}
public class Foo extends Bar
{
}
company - SAS Institute Inc. , email - ###@###.###
======================================================================
- duplicates
-
JDK-4090460 (reflect) Method.invoke() -- can't call methods privately inherited.
-
- Closed
-