Skip to content

Error when formatting text blocks with the command-line tool #1205

@borisenko-i

Description

@borisenko-i

This issue is relevant only for the command line tool (I'm using version 2.50.0), the IntelliJ IDEA plugin of the same version works correctly.

When I'm using the console tool and formatting a file containing a text block wider than 120 characters and having a trailing triple-quote """ on the same line, the formatter fails:

public class Test {
    public void doSomething() {
        var string =
                """
                aaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb cccccccccccccccc ddddddddddddddddd eeeeeeeeeeeeeeeeee fffffffffffffffff""";
    }
}

The output I'm getting in the console:

./palantir-java-format -r --palantir ~/Test.java
/Users/ilya.borisenko/Test.java:error: Something has gone terribly wrong. Please file a bug: https://github.com/palantir/palantir-java-format/issues/new

=== Actual: ===
package com.fivetran.database.account;

public class Test {

    public void doSomething() {
        /*missing*/ string = "aaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb cccccccccccccccc ddddddddddddddddd\"\n    + \" eeeeeeeeeeeeeeeeee fffffffffffffffff";
    }
}
=== Expected: ===
package com.fivetran.database.account;

public class Test {

    public void doSomething() {
        /*missing*/ string = "aaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb cccccccccccccccc ddddddddddddddddd eeeeeeeeeeeeeeeeee fffffffffffffffff";
    }
}

Moving the trailing triple-quote to a new line solves the problem, and the formatter doesn't fail if I define the string like this:

var string =
        """
        aaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb cccccccccccccccc ddddddddddddddddd eeeeeeeeeeeeeeeeee fffffffffffffffff
        """;

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