Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1262086

(reflect) java.lang.Class.getSuperclass method is not compatible to specification

XMLWordPrintable

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified



      Name: saf@russia Date: 08/05/96


      This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).

      The java.lang.Class.getSuperclass method does not work with interface
      names according to the Java language specification.

      The Java Language specification
      (Pre-Release Version 1.0, Draft 5.2 - July 3, 1996)
      says the following (please see item 20.3.4):

      "20.3.4 public Class getSuperclass()

      If this Class object represents any class other than the class Object, then the Class that represents the superclass of that class is returned. If
      this Class object is the one that represents the class Object, or if it represents an interface, null is returned. If this Class object represents an
      array class, then the Class that represents class Object is returned. "

      So the Class.getSuperclass() method should return null pointer
      if passed an interface name as argument.
      But if fact it does not.
       
      Here is the minimized test demonstrating the bug:
          

      ----- gs.java ---------------------------------------
      public class gs{

         public static void main( String[] argv ) {
           try {
             Class o1 = Class.forName("Test0403");
             Class s = o1.getSuperclass();
      // There are no superclasses for interfaces, hence
      // getSuperclass must return null
             System.out.println("Here must be null: " + s);

           } catch(ClassNotFoundException e) {
           }
         }
      }

      ----- Test0403.java -----------------------------------
      interface Test0403 {
       void doIt();
      }

      ----- The output of the test: -------------------------

      $JAVA gs
      Here must be null: class java.lang.Object

      -------------------------------------------------------


      Workaround:
      None
      ======================================================================

            nsaraiyasunw Nakul Saraiya (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: