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

Bug 369295

Summary: [extract method] Extract code in a method that returns generic type causes compilation error
Product: [Eclipse Project] JDT Reporter: Milos Gligoric <milos.gligoric>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, markus.kell.r, reprogrammer
Version: 3.7.1   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Milos Gligoric CLA 2012-01-20 16:11:39 EST
Build Identifier: Version: 3.7.1 Build id: I20110613-1736

Extract method refactoring introduces incorrect return type for the extracted method.

Reproducible: Always

Steps to Reproduce:
1. Mark "toExtract(list)" in the example below
2. Perform ExtractMethod refactoring
3. The resulting code is not compilable

class ExtractMethod {

    class C {
        void m() {
        }
    }

    <T extends Comparable<? super T>> void method(List<T> list) {
        toExtract(list).m();
    }

    static <T extends Comparable<? super T>> C toExtract(List<T> list) {
        return null;
    }
}
Comment 1 Mohsen Vakilian CLA 2012-01-21 07:54:14 EST
Refactorings have a few other bugs in handling generics (See Bug 94639, Bug 240353, and Bug 357998).
Comment 2 Deepak Azad CLA 2012-01-21 13:13:51 EST
We were not copying the type bounds, simple fix.

Fixed in master - e5035aaa0b268ce1b0110eaddb3424e954aa45eb