Bug 540208 - [Photon] JDT compiler fails to infer correctly generic types when mixing raw and generic types
Summary: [Photon] JDT compiler fails to infer correctly generic types when mixing raw ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 8
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 528970
Blocks:
  Show dependency tree
 
Reported: 2018-10-17 04:55 EDT by Thomas Naskali CLA
Modified: 2022-08-24 11:38 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Naskali CLA 2018-10-17 04:55:30 EDT
The following code (requires guava 18.0) shows a compile error "The method closed(C, C) in the type Range is not applicable for the arguments (Entity, Entity)" When upgrading to Photon. This happens in other situations too when mixing raw and generic types.

The code compiles just fine outside of Eclipse via the Java compiler (tried with both IBM and Oracle JDKs) as well as in Eclipse Oxygen.

example #1 (error):

public final class Entity implements Comparable {

	private int index = 1;

	public Entity(int index) {
		this.index = index;
	}

	public int compareTo(Object o) {
		return index;
	}

}

import com.google.common.collect.Range;

public class Test {

	public static void main(String[] args) {
		Entity d1 = new Entity(1);
		Entity d2 = new Entity(2);
		Range<Entity> r = Range.closed(d1, d2);
	}

}


This only happens if you don't specify an argument type for the Comparable generic interface in the Entity class.

example #2 (no error):

public final class Entity implements Comparable<Entity> {

	private int index = 1;

	public Entity(int index) {
		this.index = index;
	}

	public int compareTo(Entity o) {
		return index;
	}

}

import com.google.common.collect.Range;

public class Test {

	public static void main(String[] args) {
		Entity d1 = new Entity(1);
		Entity d2 = new Entity(2);
		Range<Entity> r = Range.closed(d1, d2);
	}

}


Interestingly if you declare the Entity class as a static inner class within the main class where it's used, then the error disappears !

example #3 (no error)

public class Test {

	public static void main(String[] args) {
		Entity d1 = new Entity(1);
		Entity d2 = new Entity(2);
		Range<Entity> r = Range.closed(d1, d2);
	}

	public static final class Entity implements Comparable {

		private int index = 1;

		public Entity(int index) {
			this.index = index;
		}

		public int compareTo(Object o) {
			return index;
		}

	}
	
}
Comment 1 Thomas Naskali CLA 2018-10-17 04:58:07 EDT
This issue is considered critical as it means a no-go for us because the non-generic interfaces we use are coming from a 3rd party library (joda-time 1.6.2) and we cannot afford to upgrade at the moment.
Comment 2 Till Brychcy CLA 2018-10-17 12:23:52 EDT
This is caused by commit ec76c89defa5f96571519ef98af5fe717abfdb09 for bug 528970.

Unfortunately that is about an underspecified area in the JLS and it is unclear what javac is doing.
Comment 3 Eclipse Genie CLA 2022-08-24 11:38:02 EDT
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.

If you have further information on the current state of the bug, please add it. 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.