Bug 497417 - [1.5][compiler] type argument inconsistency not detected
Summary: [1.5][compiler] type argument inconsistency not detected
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-07-06 13:50 EDT by Xuanchi Yu CLA
Modified: 2022-07-20 12:11 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 Xuanchi Yu CLA 2016-07-06 13:50:46 EDT
Code to reproduce bug:

class JavaGenericsBug {
	static class A<T> {
		T t;

		A() {

		}

		A(T t) {
			this.t = t;
		}
	}

	static class B<T1 extends A<T2>, T2> {
		T1 t1;

		B(T1 t1, T2 t2) {
			this.t1 = t1;
			this.t1.t = t2;
		}

		<NT2> B<T1, NT2> copyTo(NT2 nt2) {
			return new B<T1, NT2>(t1, nt2);
		}
	}

	public static void main(String args[]) {
		B<A<Integer>, Integer> b = new B<A<Integer>, Integer>(new A<Integer>(), 12450);
		Integer boom = b.copyTo("BOOM!!").t1.t;
		System.out.print(boom);
	}
}

Code on top will cause ClassCastException with no any type cast. And can be compiled without warning.
Comment 1 Xuanchi Yu CLA 2016-07-06 14:05:12 EDT
This is clearly to understand what happened. When try to give a type variable a wildcard type. Compiler dose not fully check the type of wildcard. On this example. Compiler dose not checked whether the wildcard type is compatible with another type variable if them have constraint.
Comment 2 Stephan Herrmann CLA 2016-07-07 07:16:52 EDT
Interesting, T1, when used as a type argument, is not within the bound of T1, when seen as a type parameter.

This is not a regression, ecj accepts this code ever since the introduction of generics.
Comment 3 Stephan Herrmann CLA 2017-04-14 18:47:38 EDT
It may be more precise to say that the type B<T1, NT2> is inconsistent, since it would require that "T1 extends A<NT2>" (by substitution of NT2), but that conflicts with the declaration of T1.

Not an inference issue.
Comment 4 Xuanchi Yu CLA 2017-06-15 09:47:49 EDT
Just attach another code may related to this issue.

public class BugTest<A> {
	public <T extends Helper1<? extends A>> void foo() {
		
	}
}

class Helper1<A extends Helper2> {
	
}

class Helper2 {
	
}
Comment 5 Manoj N Palat CLA 2018-05-17 03:23:43 EDT
bulk move out of 4.8
Comment 6 Manoj N Palat CLA 2018-08-16 00:07:39 EDT
Bulk move out of 4.9
Comment 7 Eclipse Genie CLA 2022-07-20 12:11:24 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.