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

Bug 334313

Summary: [1.5][compiler] Bug in the way eclipse handles overriding of generic abstract method by a non-abstract method
Product: [Eclipse Project] JDT Reporter: Rémi Forax <forax>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, satyam.kandula, stephan.herrmann
Version: 3.7Flags: satyam.kandula: review+
Target Milestone: 3.7.1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Patch under test
none
Patch under consideration none

Description Rémi Forax CLA 2011-01-13 14:46:13 EST
Build Identifier: I20101028-1441

Section 8.4.8.4 of JLS 3 says (see bullet 1) that the following example should compile but it don't compile.


Reproducible: Always

Steps to Reproduce:
Try to compile that code:
abstract class C<T> {
    public abstract Object foo(T x);
    public Integer foo(String x){ return 1; }
    public void bar(T x){
        System.out.println(foo(x));
    }
}

class E extends C<String> {
    public static void main(String args[])
    {
        new E().bar(null);
    }
}
Comment 1 Olivier Thomann CLA 2011-01-13 14:54:29 EST
Srikanth, please investigate.
javac 1.6 and 1.7 compile this code.
Comment 2 Srikanth Sankaran CLA 2011-02-16 04:31:02 EST
See that eclipse compiles this alright:

abstract class C<T> {
    public abstract Object foo(T x);
    public void bar(T x){
        System.out.println(foo(x));
    }
}

public class X extends C<String> {
    public Integer foo(String x){ return 1; }
    public static void main(String args[])
    {
        new X().bar(null);
    }
}

Also this variation:

abstract class B<T> {
	public abstract Object foo(T x);
}
abstract class C<T> extends B<T> {
    public Object foo(String x){ return 1; }
    public void bar(T x){
        System.out.println(foo(x));
    }
}

public class X extends C<String> {
	
    public static void main(String args[])
    {
        new X().bar(null);
    }
}
Comment 3 Srikanth Sankaran CLA 2011-02-16 05:06:53 EST
Eclipse also silently compiles this code while javac
correctly complains:


abstract class B <T> {
	public abstract String foo(T x);
}
abstract class C<T> extends B<T> {
	
    public Object foo(String x){ return 1; }
}

public class X extends C<String> {
}
Comment 4 Srikanth Sankaran CLA 2011-02-16 06:29:55 EST
Created attachment 189088 [details]
Patch under test
Comment 5 Srikanth Sankaran CLA 2011-02-21 00:04:01 EST
Comment on attachment 189088 [details]
Patch under test

This patch fails some cases, back to debug.
Comment 6 Srikanth Sankaran CLA 2011-02-21 04:38:07 EST
This is a little bit more involved than my initial assessment.
I'll continue to look at it as time permits, but this may not
be before M6.
Comment 7 Srikanth Sankaran CLA 2011-05-19 07:49:03 EDT
See bug 346029 comment 6
Comment 8 Srikanth Sankaran CLA 2011-05-22 04:03:14 EDT
Created attachment 196288 [details]
Patch under consideration
Comment 9 Srikanth Sankaran CLA 2011-05-22 05:39:03 EDT
Passes all tests, Satyam, please review - TIA.
Comment 10 Satyam Kandula CLA 2011-05-23 03:04:55 EDT
Srikanth, 
Code in comment 3 still gets compiled with this patch silenty. Is this being addressed in a different bug?
Comment 11 Satyam Kandula CLA 2011-05-23 03:09:57 EDT
(In reply to comment #10)
> Srikanth, 
> Code in comment 3 still gets compiled with this patch silenty. Is this being
> addressed in a different bug?
OOps.. sorry! I was using wrong patch! I am getting the error.
Comment 12 Satyam Kandula CLA 2011-05-23 04:17:55 EDT
The patch looks good to me.
Comment 13 Srikanth Sankaran CLA 2011-05-23 05:19:04 EDT
As this is too late for 3.7, I have released this fix only in
BETA_JAVA7 branch.
Comment 14 Stephan Herrmann CLA 2011-06-30 08:41:18 EDT
Verified using patch feature 1.0.0-20110623-0900.

Just a minor nagging regarding the tests: I was confused by not finding a 
new *positive* test, although the original issue is about "should compile". 
Is there a specific rationale behind adding the unresolvable field zork,
or is that just a pseudo-random deviation to increase test coverage?
Comment 15 Srikanth Sankaran CLA 2011-06-30 08:55:51 EDT
(In reply to comment #14)

> Is there a specific rationale behind adding the unresolvable field zork,
> or is that just a pseudo-random deviation to increase test coverage?

No, it is just the result of copy/paste - since the error that is the
subject of this bug doesn't show up anymore as verified by the test,
it was left at that.