JDK-6531814 : Generics bug with Enum instanceof
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-03-07
  • Updated: 2010-04-06
  • Resolved: 2008-04-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux XXX 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
The code snippet given below does not compile

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the given code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile
ACTUAL -
It does not

ERROR MESSAGES/STACK TRACES THAT OCCUR :
X.java:5: inconvertible types
found   : java.lang.Enum<capture#262 of ?>
required: E
      if (o instanceof E) {
          ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
enum E { }

class X {
    void f(Enum<?> o) {
      if (o instanceof E) {
        return;
      }
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
use E.class.isInstance(o)

Comments
EVALUATION This bug is a duplicate of 6548436
23-04-2008