Bug 94639 - [extract constant] computes wrong insertion point with generic type using wildcard
Summary: [extract constant] computes wrong insertion point with generic type using wil...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-11 05:52 EDT by Benjamin Pasero CLA
Modified: 2020-05-18 16:46 EDT (History)
0 users

See Also:


Attachments
Class Foo (316 bytes, application/octet-stream)
2005-05-11 05:52 EDT, Benjamin Pasero CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2005-05-11 05:52:20 EDT
Version: 3.1.0
Build id: I20050509-2010

Steps to reproduce:
1.) Find the attached class Foo and open it
2.) Refactor > Extract Constant on the Method "testFailing()"

Actual Results:
Refactor is resulting in an Error

Expected Results:
Refactor working the same way it does when running it on the Method
"testWorking()"

Regards,
Ben
Comment 1 Benjamin Pasero CLA 2005-05-11 05:52:47 EDT
Created attachment 20939 [details]
Class Foo
Comment 2 Benjamin Pasero CLA 2005-05-11 05:54:08 EDT
Sorry, Caret has to be placed inside the field inside the Method Body, not the
Method Name.

Ben
Comment 3 Markus Keller CLA 2014-05-13 07:33:59 EDT
import java.util.ArrayList;

public class Foo {
    static ArrayList<? extends Number> alFailing = new ArrayList<Integer>();

    static ArrayList alWorking = new ArrayList<Integer>();

    void testWorking() {
        alWorking.get(0); // extract "alWorking" -> OK
    }

    void testFailing() {
        alFailing.get(0); // extract "alFailing" -> compile error
    }
}

The problem is that
    private static final ArrayList<? extends Number> AL_FAILING = alFailing;
is inserted as first body declaration, which gives compile error
    "Cannot reference a field before it is defined"

The bug in the implementation is that ExtractConstantRefactoring#depends(IExpressionFragment, BodyDeclaration) eventually uses JdtASTMatcher#match(SimpleName, Object) to find occurrences of "alFailing", and the implementation of match(..) ends with

    if (node.resolveTypeBinding() != name.resolveTypeBinding())

This fails to find the dependency in this case, since the declaration and the reference resolve to ArrayList with different type arguments (separate captures of the wildcard).
Comment 4 Eclipse Genie CLA 2020-05-18 16:46:44 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.