JDK-5066774 : Bad interaction between generics, instanceof, inner classes, and subclasses
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-06-22
  • Updated: 2005-12-30
  • Resolved: 2005-12-02
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.
JDK 6
6Resolved
Related Reports
Duplicate :  
Description
Name: jl125535			Date: 06/22/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
and
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
In a parameterised class, a test "this instanceof" against a non-parameterised subclass gives a compile-time error.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac -source 1.5 Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Clean compile.
ACTUAL -
Error message.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Test.java:3: inconvertible types
found   : Test<T>
required: Test.Special
    boolean DEBUG = this instanceof Special;
                    ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

public class Test<T>
{
    boolean DEBUG = this instanceof Special;

    public static class Special extends Test<String>
    {
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Cast to a non-generified version. E.g. [code]public class Test<T>
{
    boolean DEBUG = ((Test)this) instanceof Special;

    public static class Special extends Test<String>
    {
    }
}[/code]
(Incident Review ID: 280878) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
09-09-2004

EVALUATION This appears to be a bug. ###@###.### 2004-06-22 These, on the other hand, are not bugs: Boolean.TRUE instanceof Iterable Object.class instanceof Iterable new Object[]{} instanceof Iterable Boolean, Class and arrays are final, it so they can never be instances of Iterable. ###@###.### 2004-08-03
03-08-2004