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

Bug 573327

Summary: [quickfixes] Improper quickfixes proposed for loop variable
Product: [Eclipse Project] JDT Reporter: Jeff Johnston <jjohnstn>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3 CC: kalyan_prasad, noopur_gupta
Version: 4.20   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/182925
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a0e9bdf08bf914efcb4b7185628ef7d35e143ae2
Whiteboard: stalebug

Description Jeff Johnston CLA 2021-05-03 17:00:28 EDT
For the following snippet taken from UnresolvedTypesQuickFixTest.testForEachMissingType()

import java.util.*;

public class E {
    
public void foo(ArrayList<? extends HashSet<? super Integer>> list) {
    for (element: list) {
    }
}

}

A number of quick fix suggestions are made.  The first one:

Create loop variable 'element' seems to be the only valid one.

Among others are:

Create enum element
Create class element
Create interface element
Change to ElementType (java.annotation)
Change to Statement (java.sql)
Fix project setup...

I actually get many more class suggestions when running in my child Eclipse (70).  All of them but the first one are invalid choices.

First of all, they cause another error in that you have a class, interface, enum specifier but no variable aname.  When you add a variable name, none of the suggestions are compatible with the type of "list".

Also, I have found that there is some randomness on the number of suggested quickfixes which makes the test sometimes fail in running the JDT UI test suite.
The test is expecting 6 suggestions and I have seen it report 7 in the test run (including Statement and ElementType).  I have run the test locally and it succeeded.  Running in a child Eclipse I see 70 quickfixes with a lot of other class suggestions but all of the ones in the failed test show up (i.e. all 7).
Comment 1 Noopur Gupta CLA 2021-07-08 06:29:24 EDT Comment hidden (obsolete)
Comment 2 Noopur Gupta CLA 2021-07-08 06:31:24 EDT
(In reply to Noopur Gupta from comment #1)
> I20210707-1800
> 
> win32-java11
> 
> UnresolvedTypesQuickFixTest.testForEachMissingType() failed with:
Pasted the wrong stack trace above.

Here's the failure trace from build for this test:

Wrong number of proposals, is: 7, expected: 6 - Create loop variable 'element' package pack; import java.util.*; public class E { public void foo(ArrayList<? extends HashSet<? super Integer>> list) { for (HashSet<? super Integer> element: list) { } } } - Change to 'Statement' (java.sql) package pack; import java.sql.Statement; import java.util.*; public class E { public void foo(ArrayList<? extends HashSet<? super Integer>> list) { for (Statement: list) { } } } - Change to 'ElementType' (java.lang.annotation) package pack; import java.lang.annotation.ElementType; import java.util.*; public class E { public void foo(ArrayList<? extends HashSet<? super Integer>> list) { for (ElementType: list) { } } } - Create class 'element' - Create interface 'element' - Create enum 'element' - Fix project setup... package pack; import java.util.*; public class E { public void foo(ArrayList<? extends HashSet<? super Integer>> list) { for (element: list) { } } }

java.lang.AssertionError: Wrong number of proposals, is: 7, expected: 6
- Create loop variable 'element'
package pack;

import java.util.*;

public class E {
public void foo(ArrayList<? extends HashSet<? super Integer>> list) {
for (HashSet<? super Integer> element: list) {
}
}
}
- Change to 'Statement' (java.sql)
package pack;

import java.sql.Statement;
import java.util.*;

public class E {
public void foo(ArrayList<? extends HashSet<? super Integer>> list) {
for (Statement: list) {
}
}
}
- Change to 'ElementType' (java.lang.annotation)
package pack;

import java.lang.annotation.ElementType;
import java.util.*;

public class E {
public void foo(ArrayList<? extends HashSet<? super Integer>> list) {
for (ElementType: list) {
}
}
}
- Create class 'element'
- Create interface 'element'
- Create enum 'element'
- Fix project setup...
package pack;

import java.util.*;

public class E {
public void foo(ArrayList<? extends HashSet<? super Integer>> list) {
for (element: list) {
}
}
}

at org.junit.Assert.fail(Assert.java:89)
at org.eclipse.jdt.ui.tests.quickfix.QuickFixTest.assertNumberOfProposals(QuickFixTest.java:475)
at org.eclipse.jdt.ui.tests.quickfix.UnresolvedTypesQuickFixTest.testForEachMissingType(UnresolvedTypesQuickFixTest.java:1603
...
Comment 3 Noopur Gupta CLA 2021-07-08 06:41:04 EDT
Jeff, can you try to modify the example to get a stable test result?
Comment 4 Jeff Johnston CLA 2021-07-08 16:32:30 EDT
(In reply to Noopur Gupta from comment #3)
> Jeff, can you try to modify the example to get a stable test result?

Ok.
Comment 5 Eclipse Genie CLA 2021-07-08 17:54:34 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/182925
Comment 7 Eclipse Genie CLA 2023-07-05 14:37:32 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.

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.
Comment 8 Jeff Johnston CLA 2023-07-05 19:04:25 EDT
Moved to https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/657