Skip to content

Error formatting long string literal that contains "...\\t" #1186

Closed

Description

@scch-michael-pfeiffer

In version n1.24.0 of google-java-format_windows-x86-64.exe a long string literal that contains two backslashes followed by 't' results in an error.

Negative example:

  String t =
   "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\\t";

Tool invocation and error message:

$ google-java-format_windows-x86-64.exe -r --skip-removing-unused-imports  test\Test.java
Test.java:29:7: error: unclosed string literal
   "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\\t";

Positive example. This can be formatted.

  String s = "01234567890123456789012345678901234567890123456789\\t";

Update: Using parameter --skip-reflowing-long-strings avoids this error!

Activity

  1. freetheinterns commented on Jan 14, 2025

    @freetheinterns

    I'm also hitting this issue on v1.22. Notably the error also goes away if you manually reflow the string so that it complies with line length limitations.

  2. fcorsino commented on Feb 26, 2025

    @fcorsino

    Issue is still happening in 1.25.2

    Seems to have something to do with the length, the backslashes, and case of the characters. Here are some positive and negative cases.

    // This one works
    String test =  "AB\\ABCDEFGH\\ABCDEFGHIJKLMNO\\ABCEFGHIJLMNPQRSTUV\\TRUNK\\SRC\\MAIN\\WEBAPP\\WEB-INF\\ABC";
    // This one does NOT
    String test =  "ab\\abcdefgh\\abcdefghijklmno\\abcefghijlmnpqrstuv\\trunk\\src\\main\\webapp\\web-inf\\abc";
    // This one works
    String test =  "ab\\abcdefgh\\abcdefghijklmno\\abcefghijlmnpqrstuv\\trunk\\src\\main\\webapp\\web-inf\\ab";
    // This one works
    String test =  "12\\12345678\\123456789012345\\1234567890123456789\\12345\\123\\1234\\123456\\1234567\\123";
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions