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

JCK regression: Class.isAssignableFrom(Class cls) fails with an array type

XMLWordPrintable



      Name: dfC67450 Date: 09/01/98



      javadoc says about Class.isAssignableFrom:

         Determines if the class or interface
         represented by this Class object is either the same as, or is a
         superclass or superinterface of, the class or interface
         represented by the specified Class parameter. It returns true
         if so, false otherwise. If this Class object represents a
         primitive type, returns true if the specified Class parameter
         is exactly this Class object, false otherwise.

         Specifically, this method tests whether the type represented
         by the specified Class parameter can be converted to the type
         represented by this Class object via an identity conversion or
         via a widening reference conversion. See The Java Language
         Specification, sections 5.1.1 and 5.1.4 , for details.


      According to spec if cls is an array type object false should be returned
      but isAssignableFrom returns true in this case.

      This bug was introduced in JDK 1.2fcs-H


      Here is the test demonstrating the bug:
      ------------- Test.java -----------
      public class Test {

        public static void main(String args[]) {
          int intArray[] = {1, 2, 3, 4, 5};
          boolean result = String.class.isAssignableFrom(intArray.getClass());
          if (result) {
            System.out.println("Test fails");
            System.out.println("String.class.isAssignableFrom(intArray.getClass()) retruns true");
          } else {
            System.out.println("Test passes");
          }
        }
          
      }
      ---------Output from the test---------------------
      Test fails
      String.class.isAssignableFrom(intArray.getClass()) retruns true
      -------------------------------------------------

      ======================================================================

            bgomessunw Benedict Gomes (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: