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

java.util.EmptyStackException: null when invoking a static method on a null string literal in a ternary operator #3042

Closed
ADarko22 opened this issue Oct 2, 2024 · 1 comment · Fixed by #3043
Assignees
Milestone

Comments

@ADarko22
Copy link

ADarko22 commented Oct 2, 2024

Static methods invoked on a null string literal, returned from the second expression in a ternary operator, cause a java.util.EmptyStackException during the AST creation. The following code reproduces the error:

public class Reproducer {
  
  void parseFailure(Reproducer o) {
    (o != null ? o : null).bar();
  }
  
  static void bar() { }
}

Note that this is a particular corner case that happens only in the scenario reported above. There is no failure in the following cases:

public class Reproducer {
  
  void parseSuccess(Reproducer o) {
    (o == null ? null : o).bar();
    ((Reproducer) null).bar();
    null.bar();
  }

  static void bar() { }
}
@srikanth-sankaran srikanth-sankaran self-assigned this Oct 2, 2024
@srikanth-sankaran
Copy link
Contributor

Any reason you must access the static method in a non-static way ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants