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

Bug 397158

Summary: [use supertype] Inserts incorrect type argument when applied on a generic static method
Product: [Eclipse Project] JDT Reporter: Milos Gligoric <milos.gligoric>
Component: UIAssignee: Samrat Dhillon <samrat.dhillon>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: manju656, samrat.dhillon
Version: 4.2.1Flags: manju656: review? (manju656)
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug
Attachments:
Description Flags
Fix and Test none

Description Milos Gligoric CLA 2012-12-26 00:11:08 EST
Steps to reproduce:
1. See the instructions in code below
2. The resulting code does not compile

Build id: 20121114-2344

interface I<T> {
}

class C11 {

    // Invoke "Use Supertype Where Possible" on the class below and select
    // "I<T>"
    static class C12<E> implements I<E> {
    }

    static <A> C12<A> m() {
        return null;
    }
}
Comment 1 Martin Mathew CLA 2013-01-24 01:13:48 EST
The issue is reproducible using Build ID : I20130115-1300. The refactoring results in compiler error.
Comment 2 Samrat Dhillon CLA 2013-12-31 10:38:47 EST
Created attachment 238624 [details]
Fix and Test

This problem can happen not only with static methods but also with instance methods. e.g. in the code snippet below

interface I<T> {
}
class C11 {
    class C12<E> implements I<E> {
    }

    <A> C12<A> m() {
        return null;
    }
}

My fix is basically to use the type parameters that have been declared on the node where we are replacing the base type with super type.  

Another way to fix this would have been to add additional type parameters (type parameters of the super type) at the method level for the static methods and at the class level for instance methods. But this approach leads to too many type parameters and adds clutter.

This contribution complies with http://www.eclipse.org/legal/CoO.php
Comment 3 Eclipse Genie CLA 2018-12-28 11:45:02 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.

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.