-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.0
-
sparc
-
solaris_2.5
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
-------------------------------------------------
======================================================================
- duplicates
-
JDK-4170369 H regress. Externalizable.isAssignable(array of String) incorrectly returns true
- Closed