Formatter places opening """ of text block on same line as ? / : operators in ternary expressions
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
Direção de pesquisa
Comece formatando o arquivo fornecido /tmp/TernaryBug.java com /tmp/google-java-format.jar e compare o diff exibido. Rastreie como o formatter trata expressões ternárias que contêm blocos de texto e, em seguida, verifique se cada aspas triplas de abertura é o único conteúdo que não é espaço em branco na linha e se a saída esperada não entra mais em conflito com a verificação TextBlockGoogleStyleFormatting do Checkstyle.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Java
- Estrelas
- 6.2k
- Forks
- 940
- Merge médio
- 5min
- PRs com merge (30d)
- 8
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de google/google-java-format
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
google/google-java-format#1094 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
google/google-java-format#1470 · 5 reações ·
Mantenedores costumam responder em até 1 dia
-
IndexOutOfBoundsException - Wrong formatted content when dealing with latex StringTalvez livre de novo @Amlan2000 assumiu há 56 dias e não há nenhum pull request aberto. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
google/google-java-format#1439 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
unused import removal leaves extra blank line between package declaration and class Javadoc / declarationTalvez já em andamento @arimu1 assumiu há 65 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
google/google-java-format#1436 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Eclipse
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
google/google-java-format#1428 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de google/google-java-format
Issues semelhantes
-
[BUG] 订单:会员凭订单号即可取消其他会员的待付款订单(取消接口不校验订单归属)Talvez já em andamento @dadiyang assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
macrozheng/mall#1016 ·
-
[Bug] The producer summary counts an unreported client version as a second version and warns about a version mixTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
apache/rocketmq-dashboard#6110 ·
Mantenedores costumam responder em até 4 dias
-
Python 3.15 supportTalvez já em andamento @amnesiaof assumiu hoje. AbertaL: python L: python:uv
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
dependabot/dependabot-core#16524 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
`Processing lsp` never exits and leaves orphaned processesTalvez já em andamento @overcast302 assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
processing/processing4#1578 · 1 comentário ·
-
bug needs triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
PlayersCommittee/gemp-swccg-public#1174 ·
Mantenedores costumam responder em até 2 dias