Bug 242131

Summary: [null][compiler] False warning that "instanceof always yields false".
Product: [Eclipse Project] JDT Reporter: Brian Miller <Brian.Miller>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P5 CC: amj87.iitr, jarthana, jonathan_amir, markus.kell.r, Olivier_Thomann, remy.suen, stephan.herrmann
Version: 3.4   
Target Milestone: 3.6 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Brian Miller CLA 2008-07-25 18:39:16 EDT
Build ID: I20080617-2000   (3.4.0)

Steps To Reproduce:
1. Please see that there are no warnings in class Bug.
2. Disable LINE 11 by commenting it out.
3. Enable LINE 12 by uncommenting it.  See the bogus warning.

---------------- Bug.java --------------------
import static java.beans.Introspector.getBeanInfo;
import java.beans.PropertyDescriptor;
import java.lang.reflect.*;
import java.util.List;
class Bug {
	void method() throws Exception{
		for(PropertyDescriptor prop:getBeanInfo(
		  Bug.class).getPropertyDescriptors()){
			final Method get=
				prop.getReadMethod();
			final Type type; //LINE 11
			//Type type=null; //LINE 12
			final ParameterizedType kind;
			if(null!=get&&(type=get.getGenericReturnType())instanceof ParameterizedType&&
			   List.class==(kind=(ParameterizedType)type).getRawType()&&Bug.class==kind.getActualTypeArguments()[0])
				return;
		}
	}
}
Comment 1 Jonathan Amir CLA 2008-10-22 16:12:58 EDT
I run into the same problem.
Here's the code snippet:

Object obj = null;
if ((obj = "") instanceof String) {
}
Comment 2 Stephan Herrmann CLA 2011-02-28 07:10:34 EST

*** This bug has been marked as a duplicate of bug 305590 ***
Comment 3 Ayushman Jain CLA 2011-03-07 05:28:49 EST
Verified for 3.7M6 using build I20110301-1537