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

Bug 378025

Summary: Compiler fails on Inner classes in generic class
Product: [Eclipse Project] JDT Reporter: Radim Kolar <hsn>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: amj87.iitr
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Radim Kolar CLA 2012-04-29 03:42:37 EDT
Build Identifier: M20120208-0800

this code compiles with javac 1.6 but not Eclipse. Eclipse returns error:
Cannot perform instanceof check against parameterized type ChainItem. Use the form ChainItem instead since further generic type information will be erased at runtime


class test <M> {
 	public synchronized void createChain() {
		final class ChainItem {
			protected String name;
			protected String before;
			protected String after;

			/**
			 * ChainItem objects match if their name is same
			 * @see java.lang.Object#equals(java.lang.Object)
			 */
			@Override
			public boolean equals(Object obj) {
				ChainItem other;
				if (obj instanceof ChainItem)
					return true;
				// TODO Auto-generated method stub
				return false;
			}
		}
}
}

Reproducible: Always
Comment 1 Ayushman Jain CLA 2012-04-30 02:17:56 EDT
Radim, 
This is a correct syntax error. See that javac 7 also gives the same error.

However, the wording of the error in this case is not correct in eclipse. We say "Cannot perform instanceof check against parameterized type ChainItem. Use the
form ChainItem instead since further generic type information will be erased at
runtime". The suggestion in the second sentence is absurd. This happens because in normal cases ChainItem will have been a parameterized class and we'd have suggested to use the parameterized form of this class. However, here it is an inner class and is not even parameterized, but is considered as parameterized since it is enclosed by a parameterized class. Srikanth, can you check whether this latter part is spec'd or a bug? Thanks!
Comment 2 Radim Kolar CLA 2012-05-02 08:13:22 EDT
You are right. Java 7 give error too while Java 6 do not.
Comment 3 Ayushman Jain CLA 2012-05-02 08:23:35 EDT
Reducing to minor, since only wording needs to be changed.
Comment 4 Eclipse Genie CLA 2020-01-18 14:32:22 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.