Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

String wrapping is not idempotent

Đang mở
#935 3 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
tooling

Hướng nghiên cứu

Tái hiện sự cố với ví dụ TestFormat.java được cung cấp bằng cách sử dụng JAR all-deps của google-java-format 1.15.0 hoặc 1.16.0 trên Java 17. Chạy việc định dạng nhiều lần và so sánh bố cục chuỗi của switch-expression sau mỗi lần chạy. Được xem là hoàn tất khi việc định dạng tệp không thay đổi tạo ra đầu ra giống hệt nhau trong mọi lần chạy tiếp theo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

This happened with the all deps jar from github, for both versions 1.15.0 and 1.16.0.

$ java --version
openjdk 17.0.6 2023-01-17
OpenJDK Runtime Environment (build 17.0.6+10)
OpenJDK 64-Bit Server VM (build 17.0.6+10, mixed mode)

Example code is

package com.example;

public class TestFormat {

  public void main() {
    var value = 1;
    var responseMessage =
        switch (value) {
          case 1 -> "This is a long string;This is a long string;This is a long string;This is a long string;This is a long string;This is a long string;This is a long string;";
          case 2 -> "some short string";
          case 3 -> "some medium string some medium string some medium string some medium string";
        };
  }
}

Now these strings in the switch statement will be different formatted depending on how often I call google java format.
Weirdly enough, the cosium maven plugin (gjf v1.15.0) does not change the strings in this example at all. This would be preferable for me, but mostly I want a consistent format.

## executing preview only
$ java -jar /home/dev/dev/libs/google-java-format-1.15.0-all-deps.jar Testformat.java 
package com.example;

public class TestFormat {

  public void main() {
    var value = 1;
    var responseMessage =
        switch (value) {
          case 1 -> "This is a long string;This is a long string;This is a long string;This is a"
                        + " long string;This is a long string;This is a long string;This is a long"
                        + " string;";
          case 2 -> "some short string";
          case 3 -> "some medium string some medium string some medium string some medium string";
        };
  }
}

## applying changes
$ java -jar /home/dev/dev/libs/google-java-format-1.15.0-all-deps.jar -r Testformat.java 

## executing preview only
$ java -jar /home/dev/dev/libs/google-java-format-1.15.0-all-deps.jar Testformat.java
package com.example;

public class TestFormat {

  public void main() {
    var value = 1;
    var responseMessage =
        switch (value) {
          case 1 -> "This is a long string;This is a long string;This is a long string;This is a"
              + " long string;This is a long string;This is a long string;This is a long"
              + " string;";
          case 2 -> "some short string";
          case 3 -> "some medium string some medium string some medium string some medium string";
        };
  }
}

The expectation would be that once I format a file every future format call would not change anything anymore as long as nothing was changed on the file.

Ngôn ngữ chính
Java
Star
6.2k
Fork
936
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
3

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của google/google-java-format

Tất cả issue của google/google-java-format

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.