| Summary: | Quickfix "Extract to local variable" for generics replicates the error instead of fixing it | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Wolfgang Knauf <wolfgang.knauf> | ||||
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | minor | ||||||
| Priority: | P3 | ||||||
| Version: | 3.2 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Created attachment 49209 [details]
Screenshot of the quickfix suggestion.
Moving to JDT/UI Note, "Extract to local variable" is a quick assist, not a fix. Just tries to help you restructuring the code. The fix for the scenario is 'Add type parameters to 'ArrayList''. setting WORKSFORME Hi Martin, the problem in this situation is that the "Quickfix" suggestion does not help me out of this particular situation, so it should not be displayed. As you wrote in comment #3 the correct fix for my own sample might be "Add type parameters to 'ArrayList'" (not applicable to the "javax.persistence.Query.getResultList" sample anyway). Is this possible not to show the inappropriate quickfix ? Thanks Wolfgang We have two modes: If you make a real selection (select the full word), we also show quick assist if they match the given range. If you just have a cursor, we don't show the quick assists, but just the quick fixes for the problem. The reason is that sometimes you really want to peform a quick assist like 'Assign to local' even there is an error at that location. We need a way to allow this. No changes planed at the moment. Closing as it seems not possible to detect the invalid suggestion. As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you. |
This sample comes from EJB3 programming where you can query for entity beans of a certain type this way: javax.persistence.EntityManager entityManager = ...; //Create a query ("select * from MyBean") javax.persistence.Query query = entityManager.createQuery("from MyBean"); //"getResultList" returns a list with only items of "MyBean" ! java.util.List<MyBean> listMyBean = query.getResultList(); Compiler warning: Severity and Description: "Type safety: The expression of type List needs unchecked conversion to conform to List<MyBean>" Id = "1071" The code above works fine, but I think the warning is correct. Quickinfo suggests "Extract to local variable" (see attached screenshot) I created a small sample. "getArrayList()" is a method with a non-generic return value, same as "query.getResultList()". In "getArrayListGeneric()" I assign the return value of "getArrayList()" to a generic "ArrayList<Integer>". For this line the quickfix option is available. private ArrayList<Integer> getArrayListGeneric() { ArrayList<Integer> list = this.getArrayList(); return list; } private ArrayList getArrayList() { return new ArrayList<Integer>(); } If I use "Extract to local variable" this comes out: private ArrayList<Integer> getArrayListGeneric() { ArrayList arrayList = this.getArrayList(); ArrayList<Integer> list = arrayList; return list; } The newly inserted line contains the same warning ;-). This can be repeated one more time with the some result private ArrayList<Integer> getArrayListGeneric() { ArrayList arrayList = this.getArrayList(); ArrayList arrayList2 = arrayList; ArrayList<Integer> list = arrayList2; return list; } and so on...