Community
Participate
Working Groups
Example: public class Test1 extends Thread { public void run() { super.run(); yield(); System.out.println("Hello..."); } } Parser fails to handle this case. Error is reported on the line containing yield(): Syntax error on token "(", Expression expected after this token Also, all statements following this method call are just skipped, they are not presented in AST, only super.run() call is present. Expected behavior: yield() call and all following statements should be added to AST.
I can't reproduce on 4.12 / 4.15 head of today with both Java 8 / 11 libraries. Which Eclipse / JDK version are you using?
I use org.eclipse.jdt.core-3.20.0.jar. Probably, it's 4.14. "level" is set to AST.JLS13, "compliance" is JavaCore.VERSION_13, preview features for Java 13 are enabled.
For comparison: javac version 13: $ javac --release 13 --enable-preview Test1.java Test1.java:4: error: invalid use of a restricted identifier 'yield' yield(); ^ (to invoke a method called yield, qualify the yield with a receiver or type name) 1 error ecj (latest): $ ecj --release 13 --enable-preview Test1.java ---------- 1. ERROR in /tmp/Test1.java (at line 4) yield(); ^ Syntax error on token "(", Expression expected after this token ---------- 1 problem (1 error) If you change the call to "Thread.yield()" both compilers accept. Ergo: in whether or not a program is legal, both compilers agree. Just ecj's error message isn't very helpful in this particular situation.
tentatively putting this on the radar - no promise yet.
The worst thing in this case is that code that follows yield() is just skipped. I thought that when parser encounters other syntax errors it tries to recover somehow from them. For example, when a statement is missing a semicolon, an error is reported, but statements that follow the error are still present in AST. Is something similar possible in this case also?
Bulk move out of 4.16
keeping in the radar for 4.18
bulk move out of 4.19 - retarget once an owner is assigned