United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4749904 : Class.getDeclaringClass() throws unexpected exception

Details
Type:
Bug
Submit Date:
2002-09-19
Status:
Closed
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2002-11-13
Component:
hotspot
OS:
solaris_2.6
Sub-Component:
runtime
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:
1.4.2 (mantis)

Related Reports
Relates:

Sub Tasks

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


                                     
2004-06-14
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
                                     
2002-10-29
EVALUATION

Class.getDeclaringClass is a native method which appears to be a direct call
to JVM_GetClassDeclaringClass.

-- iag@sfbay 2002-09-19
                                     
2002-09-19



Hardware and Software, Engineered to Work Together