Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341828

Summary: Bad secondary error for unresolved type in instanceof expression
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Jay Arthanareeswaran <jarthana>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: amj87.iitr, jarthana, Olivier_Thomann, shankhba
Version: 3.7   
Target Milestone: 4.3 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Markus Keller CLA 2011-04-04 13:46:49 EDT
HEAD

The snippet below produces 2 errors:
1) FileInputStream cannot be resolved to a type
2) Incompatible conditional operand types InputStream and FileInputStream

The second error is not interesting and should not be reported as long as the RHS of the instanceof expression is not resolved.


package xy;

import java.io.InputStream;

public class Try {
    void foo(InputStream is) {
        if (is instanceof FileInputStream)
            System.out.println("Hello");
    }
}
Comment 1 Ayushman Jain CLA 2011-04-05 07:14:58 EDT
I'll take a look
Comment 2 Olivier Thomann CLA 2013-03-26 14:35:59 EDT
The fix seems trivial.
If the checkedType is not a valid binding, we should not check for checkCastTypesCompatibility(..). I'll attach a patch that can be reviewed.
Comment 3 Olivier Thomann CLA 2013-03-26 14:37:43 EDT
Created attachment 229063 [details]
Proposed fix

Regression test needs to be added and all tests need to be run. We might already have a test that returns an extra secondary error.
Comment 4 Olivier Thomann CLA 2013-03-26 14:39:12 EDT
Jay, please review.
Comment 5 Jay Arthanareeswaran CLA 2013-04-08 11:39:55 EDT
(In reply to comment #4)
> Jay, please review.

Patch looks good, will release after running the tests.
Comment 6 Jay Arthanareeswaran CLA 2013-04-08 13:12:19 EDT
Fix released here along with new tests:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=5ccdb7e247bbbd1f8f7142380f221525938bf5a9
Comment 7 shankha banerjee CLA 2013-04-30 05:10:57 EDT
Verified for 3.7 M7 using  build I20130428-2000.