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

Bug 497377

Summary: Create field hotfix does not determine correct field type
Product: [Eclipse Project] JDT Reporter: Carsten Reckord <reckord>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Carsten Reckord CLA 2016-07-06 06:36:20 EDT
Take this class:

import java.util.ArrayList;
import java.util.List;

public class Test {
   public List<Test> getOthers() {
      if (others == null) {
         others = new ArrayList<>();
      }
      return others;
   }
}

It will have compile errors due to the missing "others" field. Go to the if(...) line and apply the "Create field" hotfix. It will create this field:

   private ArrayList<Object> others;

Clearly, <Object> is the wrong type parameter for "others". It should have figured this out from other usages of the field. The return statement together with the method signature clearly indicates that the correct type parameter to use would have been <Test>.

What's more, the created field has addressable spans for the type and the name that I can tab into, which is nice to correct any issues quickly (e.g. the obligatory ArrayList->List change). But the type span covers the whole type expression including generics. It would be a lot nicer if I could tab into the type parameter(s) separately.
Comment 1 Carsten Reckord CLA 2016-07-06 06:39:41 EDT
Oops, I made an error in the description, and it's even worse: The aforementioned wrong generics happen if you apply the hotfix on the "new ArrayList" line. If you do it on the if(...) line, the generated field is of type Object, which is even less helpful...

Updated the summary accordingly.
Comment 2 Eclipse Genie CLA 2020-01-19 04:44:25 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. 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.