safe navigation in while condition clause not fully evaluated
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the generated Java while-loop shown in the issue and trace how the safe-navigation expression is evaluated across loop iterations. Done means the full a?.b?.c condition is reevaluated each time, so the loop stops when getB() returns null; add or run a regression test covering this example.
Written by the indexing model from the issue text.
Description
class A {
B b;
Integer limit = 3
new (){
b = new B()
b.c = new C()
}
def getB(){
limit --
if(limit == 0){
return null
}else{
return b
}
}
def getLimit(){
return limit;
}
}
class B {
C c;
def setC(C c){
this.c = c
}
def getC(){
return c;
}
}
class C {
}
class Test {
def static void main(String[] args) {
val A a = new A();
while(a?.b?.c != null){
println(a.limit)
}
}
}
The code runs in infinite loop.
Generated Java code:
public class Test {
public static void main(final String[] args) {
final A a = new A();
B _b = null;
if (a!=null) {
_b=a.getB();
}
C _c = null;
if (_b!=null) {
_c=_b.getC();
}
boolean _notEquals = (!Objects.equal(_c, null));
boolean _while = _notEquals;
while (_while) {
Integer _limit = a.getLimit();
InputOutput.<Integer>println(_limit);
C _c_1 = null;
if (_b!=null) {
_c_1=_b.getC();
}
boolean _notEquals_1 = (!Objects.equal(_c_1, null));
_while = _notEquals_1;
}
}
}
In the end of the while loop, the 'a?.b' of 'a?.b?.c' is not evaluated again, causing the condition not updated.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from eclipse-xtext/xtext
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eclipse-xtext/xtext#3727 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eclipse-xtext/xtext#3668 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
eclipse-xtext/xtext#3797 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
eclipse-xtext/xtext#3796 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
eclipse-xtext/xtext#3795 · 1 comment ·
All issues in eclipse-xtext/xtext
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
objectionary/hone-maven-plugin#1061 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
spring-projects/spring-modulith#1895 ·