JDK-4137722 : getDeclaredMethods() returns NULL (no exception)
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.1.4,1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5.1,windows_nt
  • CPU: x86,sparc
  • Submitted: 1998-05-12
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
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.1.8 1.1.8Fixed
Related Reports
Duplicate :  
Description

Name: el35337			Date: 05/12/98


Problem: If a class A refers to a class B,
and if B is not in classpath, then I can
still load class A by Class.forName call
(should it work???) and then if I call 
getDeclaredMethods() on class A then the call
returns NULL. From the docs, I suppose it
should either throw an exception or return
an array of Method[] of length 0. The strange
thing is that the getMethods() call on class
A returns an array of finite length.

1) Should the class A be loaded at all if
it refers to B and B is not in classpath?
2) Shouldn't getDeclaredMethods() call throw
an exception if class A is loaded at all
and B is not in classpath?
3) In any case shouldn't getMethods and
getDeclaredMethods return similar results (I
mean either throw an exception or return a
non-NULL array)?

Sample Code

I have a class aaaa which refers to bbbb.
Compile both and then remove bbbb from 
class path. Run "java aaaa".

aaaa.java
===========
import java.lang.*;
import java.lang.reflect.*;
import bbbb;

public class aaaa extends Object{

  public void xyz() {

  }

  public bbbb zzz () {
    return null;
  }

  public static void main (String [] args) {

    try {
      Class c = Class.forName ("aaaa");
      Method [] mm = c.getDeclaredMethods();

      System.out.println ("c is : " + c);
      if (mm == null)
          System.out.println ("mm is null");
      else
          System.out.println (mm + "   " + mm.length);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

bbbb.java
=========
import java.lang.*;

public class bbbb extends Object {

  public void xyz() {

  }

}

- ajay apte
###@###.###
(Review ID: 30106)
======================================================================

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

EVALUATION Reproduced in 1.1.6, 1.1.5, and 1.1. Cannot reproduce in 1.2_ea2, 1.2beta2, and 1.2beta4-F: gives NoClassDefFoundError as expected. Note that the VM is allowed to load A without loading B, though B will eventually have to be loaded during the execution of the example given. I am closing this as not reproducible (in 1.2). william.maddox@Eng 1998-05-14 ------------------------------------------------------------------------ This is still reproducible in 1.1.7. I am reopening as one of our licensees is investigating a fix. mick.fleming@Ireland 1998-10-28 Added a "NoClassDefFoundError" when a class has a method which returns an object of a non-existent class. ###@###.### 1998-11-17 This problem veirfied as fixed via regression testing. john.s.lee@Eng 1999-01-21
17-11-1998

PUBLIC COMMENTS Changed reflect_find_class (in reflect.c) to throw a NoClassDefFoundError if the call to FindClassFromClass (classresolver.c) returns null. ###@###.### 1998-11-17
17-11-1998