Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

String wrapping is not idempotent

オープン
#935 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
tooling

調査の方向性

Java 17 上で google-java-format 1.15.0 または 1.16.0 の all-deps JAR を使用し、提供された TestFormat.java の例で問題を再現します。フォーマットを繰り返し実行し、各パス後の switch-expression の文字列レイアウトを比較します。変更していないファイルをフォーマットした結果が、その後の実行ごとに同一の出力になることを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
6.2k
フォーク
936
平均マージ
6分
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/google-java-format のほかの issue

google/google-java-format の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。