Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353354 - Compile error when using "instanceof" on an inner class when outer class is generified
Summary: Compile error when using "instanceof" on an inner class when outer class is g...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-28 14:13 EDT by Dan Richter CLA
Modified: 2011-07-28 14:49 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Richter CLA 2011-07-28 14:13:00 EDT
Build Identifier: I20100129-1300

Eclipse gives a compiler error in the "test()" method of the following class:

    class OuterClass<T> {
        class BaseClass { }
        class SubClass extends BaseClass { }

        public void test(BaseClass myObject) {
            boolean b = (myObject instanceof OuterClass.SubClass);
        }
    }

The error is: "Incompatible conditional operand types MyOuterClass<T>.MyBaseClass and MyOuterClass.MySubClass"

However, Sun's JVM (build 1.6.0_22-b04), which Eclipse is using, compiles the class without an error.

This bug HAS ALREADY BEEN FIXED: it does not occur in Eclipse build M20110210-1200. I am only entering this bug to document it.

Reproducible: Always
Comment 1 Dan Richter CLA 2011-07-28 14:16:07 EDT
Just for the record, Eclipse correctly flags the following lines as errors:
  boolean b1 = (myObject instanceof SubClass);
  boolean b2 = (myObject instanceof SubClass<T>);
  boolean b3 = (myObject instanceof SubClass<?>);
  boolean b4 = (myObject instanceof OuterClass<T>.SubClass);
  boolean b5 = (myObject instanceof OuterClass.SubClass<T>);
  boolean b6 = (myObject instanceof OuterClass.SubClass<?>);

Also for the record, I initially posted a question about this to StackOverflow: http://stackoverflow.com/questions/6849591/problem-with-instanceof-with-generic-outer-class
Comment 2 Dan Richter CLA 2011-07-28 14:17:03 EDT
Because this bug does not occur in build M20110210-1200, I am marking this bug resolved.
Comment 3 Ayushman Jain CLA 2011-07-28 14:49:25 EDT
(In reply to comment #0)
> However, Sun's JVM (build 1.6.0_22-b04), which Eclipse is using, compiles the
> class without an error.

Just to clarify: JVM does not "compile" code. The compiler does. And if you did mean the compiler, note that Eclipse does not use the Sun javac compiler. We have our own Eclipse Compiler for Java(ECJ).

> This bug HAS ALREADY BEEN FIXED: it does not occur in Eclipse build
> M20110210-1200. I am only entering this bug to document it.

I guess there's no point opening a bug when you don't see it any more. We always fix bugs in the open so there will always be a bug that has been used to fix this patch. Thanks anyway.