| Summary: | Foreach variable not found if ternary operator incomplete | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Stefano Rocca <s.rocca> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | s.rocca, srikanth_sankaran |
| Version: | 4.3 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | stalebug | ||
Thanks for the defect report. I can reproduce it. It is going to take us several months to get to this unfortunately though. We are all very busy with Java 8 implementation work. 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. |
In the following code the ternary operator is incomplete and Eclipse correctly reports a syntax error. The problem is that a the row above appears another error (s cannot be resolved) about the variable of the foreach loop: import java.util.ArrayList; public class Test { public Test() { ArrayList<String> ls = new ArrayList<String>(); for (String s : ls) { System.out.println(s); // s cannot be resolved s = s != null ? s.concat(s); // syntax error } } } If I complete the ternary operator, both errors disappear. This example is trivial, but I encountered this error in a more complex scenario, with three nested foreach and the variables declared in each foreach where not resolved: import java.util.ArrayList; public class Test { public Test() { ArrayList<String> ls = new ArrayList<String>(); ArrayList<String> lt = new ArrayList<String>(); ArrayList<String> lu = new ArrayList<String>(); for (String u : lu) { for (String t : lt) { for (String s : ls) { System.out.println(s); // s not resolved System.out.println(t); // t not resolved System.out.println(u); // u not resolved s = s != null ? s.concat(s); // syntax error } } } } } Furthermore, changing the foreach to a for as in this example: import java.util.ArrayList; import java.util.Iterator; public class Test { public Test() { ArrayList<String> ls = new ArrayList<String>(); for (Iterator<String> iter = ls.iterator(); iter.hasNext();) { String s = iter.next(); System.out.println(s); s = s != null ? s.concat(s); // syntax error } } } Resolves the problem (i.e. there's only the syntax error)