United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4081023 Class.isInstance() returns true while null instanceof X is always false
4081023 : Class.isInstance() returns true while null instanceof X is always false

Details
Type:
Bug
Submit Date:
1997-09-23
Status:
Closed
Updated Date:
2012-09-28
Project Name:
JDK
Resolved Date:
1997-10-01
Component:
core-libs
OS:
windows_nt
Sub-Component:
java.lang:reflect
CPU:
x86
Priority:
P3
Resolution:
Duplicate
Affected Versions:
1.2.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: sg39081			Date: 09/23/97


Possible regression...

// This program should print out
//
// - instanceof
// - isInstance
//
// as it does under jdk 114. Instead it prints
//
// - instanceof
// + isInstance

public class testinstance {

  public static void main(String[] argv) throws Exception {

    if (null instanceof String) {
      System.out.println("+ instanceof");
    } else {
      System.out.println("- instanceof");
    }

    if (Class.forName("java.lang.String").isInstance(null)) {
      System.out.println("+ isInstance");
    } else {
      System.out.println("- isInstance");
    }
  }
}
======================================================================

                                    

Comments
WORK AROUND



Name: sg39081			Date: 09/23/97


Check for null before using this method.
======================================================================
                                     
2004-06-11
EVALUATION

Since the native method in java.lang.Class is now implemented in terms of
JNI, this bug is being caused by the bug in JNI -- 4074494.

anand.palaniswamy@Eng 1997-10-01
                                     
1997-10-01



Hardware and Software, Engineered to Work Together