Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECJ accepts invalid syntax without error #367

Closed
alienisty opened this issue Sep 4, 2022 · 2 comments · Fixed by #1047
Closed

ECJ accepts invalid syntax without error #367

alienisty opened this issue Sep 4, 2022 · 2 comments · Fixed by #1047
Assignees
Labels
bug Something isn't working compiler Eclipse Java Compiler (ecj) related issues
Milestone

Comments

@alienisty
Copy link

The following Java code is accepted without errors by eclipse:

public class EclipseParserBug {
  private static void copy(boolean[] src, boolean[] dst) {
    long start=System.nanoTime();
    IntStream.range(0, src.length).parallel().forEach(i -> dst[i] = src[i]))); 	  
    System.out.println("Copy took: " + (System.nanoTime() - start));
  }
}

which is compiled in the following byte code:

// Compiled from EclipseParserBug.java (version 1.8 : 52.0, super bit)
public class EclipseParserBug {
  
  // Method descriptor #6 ()V
  // Stack: 1, Locals: 1
  public EclipseParserBug();
    0  aload_0 [this]
    1  invokespecial java.lang.Object() [8]
    4  return
      Line numbers:
        [pc: 0, line: 1]
      Local variable table:
        [pc: 0, pc: 5] local: this index: 0 type: EclipseParserBug
  
  // Method descriptor #15 ([Z[Z)V
  // Stack: 2, Locals: 4
  private static void copy(boolean[] src, boolean[] dst);
    0  invokestatic java.lang.System.nanoTime() : long [16]
    3  lstore_2 [start]
    4  return
      Line numbers:
        [pc: 0, line: 3]
        [pc: 4, line: 8]
      Local variable table:
        [pc: 0, pc: 5] local: src index: 0 type: boolean[]
        [pc: 0, pc: 5] local: dst index: 1 type: boolean[]
        [pc: 4, pc: 5] local: start index: 2 type: long
}

which is also incorrect.
Note how only the first line of the source code has been compiled, despite having debug information for the rest.
It seems like a very corner case but it could lead to very sneaky and hard to find bugs.

@alienisty alienisty changed the title Eclipse compiler accepts invalid syntax without error ECJ accepts invalid syntax without error Sep 4, 2022
@stephan-herrmann
Copy link
Contributor

Looks like https://bugs.eclipse.org/bugs/show_bug.cgi?id=553601

When addressing this issue, we should also add the test case from the other bug.

@trancexpress
Copy link
Contributor

trancexpress commented Apr 3, 2023

Should be the same as #859 and #125.

@trancexpress trancexpress added bug Something isn't working compiler Eclipse Java Compiler (ecj) related issues labels Apr 3, 2023
@srikanth-sankaran srikanth-sankaran self-assigned this May 10, 2023
srikanth-sankaran added a commit to srikanth-sankaran/eclipse.jdt.core that referenced this issue May 11, 2023
The well intentioned suppression of the user non-actionable message
"Syntax error, insert ElidedSemicolonAndRightBrace to complete
LambdaBody" sometimes backfires - For example, when it is the ONLY
syntax error reported by DiagnoseParser. Rather than completely suppress
this message, surface a more general syntax error if there are no other
syntax errors

Fixes: eclipse-jdt#367
srikanth-sankaran added a commit that referenced this issue May 11, 2023
The well intentioned suppression of the user non-actionable message
"Syntax error, insert ElidedSemicolonAndRightBrace to complete
LambdaBody" sometimes backfires - For example, when it is the ONLY
syntax error reported by DiagnoseParser. Rather than completely suppress
this message, surface a more general syntax error if there are no other
syntax errors

Fixes: #367
@iloveeclipse iloveeclipse added this to the 4.28 M3 milestone May 11, 2023
subyssurendran666 pushed a commit to subyssurendran666/eclipse.jdt.core that referenced this issue Jul 18, 2023
The well intentioned suppression of the user non-actionable message
"Syntax error, insert ElidedSemicolonAndRightBrace to complete
LambdaBody" sometimes backfires - For example, when it is the ONLY
syntax error reported by DiagnoseParser. Rather than completely suppress
this message, surface a more general syntax error if there are no other
syntax errors

Fixes: eclipse-jdt#367
robstryker pushed a commit to robstryker/eclipse.jdt.core that referenced this issue Jul 18, 2024
The well intentioned suppression of the user non-actionable message
"Syntax error, insert ElidedSemicolonAndRightBrace to complete
LambdaBody" sometimes backfires - For example, when it is the ONLY
syntax error reported by DiagnoseParser. Rather than completely suppress
this message, surface a more general syntax error if there are no other
syntax errors

Fixes: eclipse-jdt#367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Eclipse Java Compiler (ecj) related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants