| Summary: | Java parser failure: a incorrect code compiles and runs wrongly | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Joël DRIGO <joel.drigo> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | major | ||
| Priority: | P3 | CC: | igor, jarthana, stephan.herrmann |
| Version: | 4.6 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 8 | ||
| Whiteboard: | stalebug | ||
Moving to JDT Core!! Reproduced in master. Keeping it in 4.7 list. It's not the extra parenthesis but the following sysout that throws the compiler off track. With out that, we do report an error. Looks like the DiagnoseParser does not see the LambdaExpression when the following statement is present, the resulting method AST does not have any statements in the body. Needs a little more investigation Simpler example, Eclipse 4.7M6 does not flag the extra )) as errors. Possibly related to bug 383046 public class A { java.util.function.Function<String, Boolean> L = (str) -> str.length() <= 0)); }; 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. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. 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. |
Hi, An extra parenthesis in method invocation with lambdas as parameters isn't detected by the Java parser. The class compiles, and runs, doing not what it should do. The environment is: Version: Neon.2 Release (4.6.2) Build id: 20161208-0600 Java 8_u102 (with javac, I get a compilation error). Windows 8.1 Here is a snippet to show the problem: public class Snippet { public static void main(String[] args) { System.out.println("starting..."); if ( false ) { System.out.println("this is executed, but it should not !?"); } else { System.out.println("this is still executed..."); exampleMethod(42, id1-> (p1, id2)-> otherMethod())); // The last extra parenthesis causes the parser to fail } System.out.println("...finishing"); } public static interface I1 { I2 create(String id); } public static interface I2 { Class1 get(Class2 something, String somethingElse); } public static class Class1 { } public static class Class2 { } public static void exampleMethod(int param1, I1 param2) { System.out.println("example method is invoked"); } public static Class1 otherMethod() { System.out.println("other method is invoked"); return new Class1(); } } I should not compile, but it do. The result of the run is wrong: starting... this is executed, but it should not !? this is still executed... The parser is deceived and completely delirious. If you try the following code (I replaced method name with whatever), it compiles and runs too, with same result as previous: public class Snippet { public static void main(String[] args) { System.out.println("starting..."); if ( false ) { System.out.println("this is executed, but it should not !?"); } else { System.out.println("this is still executed..."); something(42, id1-> (p1, id2)-> crazy())); // The last extra parenthesis causes the parser to fail } System.out.println("...finishing"); } public static interface I1 { I2 create(String id); } public static interface I2 { Class1 get(Class2 something, String somethingElse); } public static class Class1 { } public static class Class2 { } public static void exampleMethod(int param1, I1 param2) { System.out.println("example method is invoked"); } public static Class1 otherMethod() { System.out.println("other method is invoked"); return new Class1(); } }