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

[String templates] Internal compiler error: java.lang.NegativeArraySizeException: -3 at Scanner.getCurrentTokenInRange(Scanner.java:525) #1722

Closed
srikanth-sankaran opened this issue Dec 11, 2023 · 3 comments
Assignees
Milestone

Comments

@srikanth-sankaran
Copy link
Contributor

While playing around with the example in #1719 I ended up with a
NegativeArraySizeException when compiling this snippet:

public class X {
  public static void main(String[] args) {
    String firstName = "Bill", lastName = "Duck";
    System.out.println(STR."\{firstName} \{lastName}");

    String title = "My Web Page";

    String html = STR."""
        </head>
      """;
    System.out.println(html);
  }
}
@srikanth-sankaran srikanth-sankaran changed the title Internal compiler error: java.lang.NegativeArraySizeException: -3 at Scanner.getCurrentTokenInRange(Scanner.java:525) [String templates] Internal compiler error: java.lang.NegativeArraySizeException: -3 at Scanner.getCurrentTokenInRange(Scanner.java:525) Dec 11, 2023
@srikanth-sankaran srikanth-sankaran added this to the 4.31 M1 milestone Dec 11, 2023
@srikanth-sankaran
Copy link
Contributor Author

srikanth-sankaran commented Dec 11, 2023

This compiles fine:

public class X {
  public static void main(String[] args) {
    String firstName = "Bill", lastName = "Duck";
    System.out.println(STR."\{firstName} \{lastName}");

    String title = "My Web Page";

    String html = STR."""
    //      <title>\{title}</title>
        </head>
      """;
    System.out.println(html);
  }
}

Deleting the line // <title>\{title}</title> causes the crash

@srikanth-sankaran
Copy link
Contributor Author

Crash also with:

public class X {
  public static void main(String[] args) {
    String firstName = "Bill", lastName = "Duck";
    System.out.println(STR."\{firstName} \{lastName}");

    String title = "My Web Page";

    String html = STR."""
    
      """;
    System.out.println(html);
  }
}

@jarthana
Copy link
Member

Pull #1730 took care of this. Closing.

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

No branches or pull requests

2 participants