Bug 506396 - [1.8][compiler][generics] Generics bug when overriding method cause CCE
Summary: [1.8][compiler][generics] Generics bug when overriding method cause CCE
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: Srikanth Sankaran CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-22 21:38 EDT by Xuanchi Yu CLA
Modified: 2023-06-01 06:21 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 Xuanchi Yu CLA 2016-10-22 21:38:52 EDT
Code to reproduce bug:

public class OverrideGenericsBug {
	public interface A<T> {
		<R extends T> A<R> test();

		T get();
	}

	public static class B implements A<CharSequence> {
		@Override
		public B test() {
			return this;
		}

		@Override
		public CharSequence get() {
			return new StringBuilder();
		}
	}

	public static void main(String[] args) {
		A<CharSequence> obj = new B();
		A<String> what = obj.<String>test();
		String string = what.get();
		System.out.println(string);
	}
}

Eclipse compiler compiled this code without any warning. Javac compiler warning about this code.
Comment 1 Xuanchi Yu CLA 2016-10-22 21:59:48 EDT
So "A" is an interface. "A" has a type TypeVariable "<T>".
The method "test()" in "A" returns another "A" but we can change "<T>" to its subtype.

Now "B" is ParameterizedType extends "A" and "<T>" parameterized to "CharSequence".
The problem is we can override "test()" and returns "B" without any warning. This is looks fine but if we have a varible "A<CharSequence> obj" pointer to object "B". We can just call "obj.<ANY_SUB_TYPE>test()" to let things go wrong.

Javac doesn't reject this code but warning about. Because it described in JLS§8.4.5
Comment 2 Stephan Herrmann CLA 2017-04-01 13:32:48 EDT
Found this only now. Agree that ecj should raise a warning, too.
Comment 3 Manoj N Palat CLA 2018-05-16 01:30:34 EDT
Bulk move out of 4.8
Comment 4 Eclipse Genie CLA 2020-08-07 14:31:26 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.
Comment 5 Eclipse Genie CLA 2022-08-10 17:12:43 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.