JDK-4749904 : Class.getDeclaringClass() throws unexpected exception
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: generic
  • Submitted: 2002-09-19
  • Updated: 2012-10-08
  • Resolved: 2002-11-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Relates :  
Description
Class.getDeclaringClass() throws IllegalAccessError when called on an instance of Class representing java/awt/LightweightDispatcher. Please see an example below (reproducible with 1.4.0, 1.4.1, 1.4.2) The same example works correctly with 1.3.1 and returns null since java/awt/LightweightDispatcher is not an inner class.

package Fish;
import java.lang.reflect.*;
import java.io.*;
public class A
{

	public static void main(String[] args)
	{

		Class base = new java.awt.Container().getClass();
		ObjectStreamClass ocs = ObjectStreamClass.lookup(base);
		ObjectStreamField field = ocs.getField("dispatcher");
		Class cls = field.getType();
		System.out.println("Class type is "+cls.getName());
		Class dcl = cls.getDeclaringClass();
		System.out.println("Declaring class is "+dcl);
	}

}

class type is java.awt.LightweightDispatcher
  java.lang.IllegalAccessError: try to access class
sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher from class
java.awt.LightweightDispatcher
          at java.lang.Class.getDeclaringClass(Native Method)

Looking at the code in the debugger, getDeclaringClass() finds that the inner_classes field is not empty. It then tries to access constant pool at the offset in inner_classes and fails. Since java/awt/LightweightDispatcher is not an inner class, it seems strange that inner_classes field is not empty.


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis
14-06-2004

SUGGESTED FIX In JVM_GetDeclaringClass and JVM_GetDeclaredClasses, we load the class at an inner table attribute to see if it's the same as the class object passed in. Check that the names of the classes match before attempting the loads. update: src/share/vm/oops/constantPoolOop.cpp update: src/share/vm/oops/constantPoolOop.hpp update: src/share/vm/prims/jvm.cpp Note that this problem can only be reproduced pre-b03 in Mantis, because of bug 4768967; the class file was incorrect. This code is still good as it avoids some potential class loading during the GetDeclaringClass, GetDeclaredClass calls. Updated test case attached to bug report. java Test expected results: Class type is TestClass$Foo Declaring class is class TestClass Class type is java.awt.LightweightDispatcher Declaring class is null result before fix: Class type is TestClass$Foo Declaring class is class TestClass Class type is java.awt.LightweightDispatcher Exception in thread "main" java.lang.IllegalAccessError: tried to access class sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher from class java.awt.LightweightDispatcher at java.lang.Class.getDeclaringClass(Native Method) at Test.main(Test.java:25) ###@###.### 2002-10-29
29-10-2002

EVALUATION Class.getDeclaringClass is a native method which appears to be a direct call to JVM_GetClassDeclaringClass. -- iag@sfbay 2002-09-19
19-09-2002