Formatter places opening """ of text block on same line as ? / : operators in ternary expressions
まだ誰も着手していません。
評価
調査の方向性
まず、提供された /tmp/TernaryBug.java を /tmp/google-java-format.jar でフォーマットし、表示された diff と比較します。テキストブロックを含む三項式を formatter がどのように処理するかを追跡し、その後、各開始 triple quote がその行で空白以外の唯一の内容であること、また期待される出力が Checkstyle の TextBlockGoogleStyleFormatting チェックと競合しなくなっていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Description
google-java-format formats ternary expressions containing text blocks such that the opening """ is placed on the same line as the ? and : operators. This appears to violate Google Java Style Guide Section 4.8.9, which states:
The opening """ of a text block is always on a new line. That line may either follow the same indentation rules as other constructs, or it may have no indentation at all (so it starts at the left margin). The closing """ is on a new line with the same indentation as the opening """, and may be followed on the same line by further code. Each line of text in the text block is indented at least as much as the opening and closing """. (If a line is indented further, then the string literal defined by the text block will have space at the start of that line.)
The key requirement is that the """ must be on a new line, but the formatter places an operator (? or :) immediately before it on the same line, meaning the """ is no longer on the new line.
Reproduction
vivek@Viveks-MacBook-Air checkstyle % cat > /tmp/TernaryBug.java << 'EOF'
class TernaryBug {
boolean flag = true;
String a = flag
? """
yes
"""
: """
no
""";
}
EOF
vivek@Viveks-MacBook-Air checkstyle % java -jar /tmp/google-java-format.jar /tmp/TernaryBug.java > /tmp/TernaryBug_formatted.java
diff -u /tmp/TernaryBug.java /tmp/TernaryBug_formatted.java
--- /tmp/TernaryBug.java 2026-04-18 18:43:21
+++ /tmp/TernaryBug_formatted.java 2026-04-18 18:43:26
@@ -1,11 +1,12 @@
class TernaryBug {
- boolean flag = true;
+ boolean flag = true;
- String a = flag
- ? """
+ String a =
+ flag
+ ? """
yes
"""
- : """
+ : """
no
""";
}
vivek@Viveks-MacBook-Air checkstyle % cat > /tmp/TernaryBug.java << 'EOF'
class TernaryBug {
boolean flag = true;
String d = flag ?
"""
yes
"""
:
"""
no
""";
}
EOF
vivek@Viveks-MacBook-Air checkstyle % java -jar /tmp/google-java-format.jar /tmp/TernaryBug.java > /tmp/TernaryBug_formatted.java
diff -u /tmp/TernaryBug.java /tmp/TernaryBug_formatted.java
--- /tmp/TernaryBug.java 2026-04-18 18:45:14
+++ /tmp/TernaryBug_formatted.java 2026-04-18 18:45:19
@@ -1,12 +1,12 @@
class TernaryBug {
- boolean flag = true;
+ boolean flag = true;
- String d = flag ?
- """
- yes
- """
- :
- """
- no
- """;
+ String d =
+ flag
+ ? """
+ yes
+ """
+ : """
+ no
+ """;
}
Expected Behavior
The formatter should place the opening"""on its own line, separate from the ? and : operators. For example:
class TernaryBug {
boolean flag = true;
String a =
flag
?
"""
yes
"""
:
"""
no
""";
}
Or any equivalent layout where """ is the only non-whitespace content on its starting line.
Why This Matters
Checkstyle's TextBlockGoogleStyleFormatting check enforces the Google Java Style Guide rule that the opening """ must be on its own line. The current formatter output directly conflicts with this check, code formatted by google-java-format produces Checkstyle violations. This creates a situation where developers cannot simultaneously satisfy both the formatter and the style checker, which are both intended to enforce the same Google Java Style Guide.
- 主要言語
- Java
- スター
- 6.2k
- フォーク
- 936
- 平均マージ
- 6分
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/google-java-format のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/google-java-format#1094 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
google/google-java-format#1450 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
google/google-java-format#1439 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
google/google-java-format#1436 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
google/google-java-format#1428 · コメント 3 件 ·
google/google-java-format の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
elastic/gradle-plugins#157 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cryptomator/hub#497 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
johanhaleby/occurrent#1120 ·