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

unused import removal leaves extra blank line between package declaration and class Javadoc / declaration

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

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

評価

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

調査の方向性

まず、TestBug.java の例と google-java-format コマンドを使って問題を再現します。未使用の import を削除し、パッケージ宣言とクラスの Javadoc の間の垂直方向の空白を処理するフォーマットパスを追跡します。最初のフォーマットパスで期待される出力と一致する空行が 1 行生成され、2 回目のパスが不要になれば完了です。

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

説明

When google-java-format removes an unused import statement located between a package declaration and class Javadoc or class declaration, it does not collapse the vertical whitespace in the same formatting pass. As a result, the formatted output contains extra blank lines (two consecutive blank lines instead of one).

Running google-java-format a second time on the output collapses the extra blank line as expected. We observed this in generated code, more context here: https://github.com/googleapis/librarian/issues/7146

Environment

  • google-java-format Version: Tested on 1.25.2 through 1.35.0 (including recent builds).
  • Operating System: Linux / macOS / Cross-platform

Minimal Reproducible Example

Input Code (TestBug.java)
```java                                                                                                                                                                                 
package com.example;                                                                                                                                                                    

import static io.grpc.MethodDescriptor.generateFullMethodName;

/**
 * Javadoc for class.
 */
public class TestBug {
}
Command Executed
google-java-format TestBug.java

Actual Output (First Pass)

package com.example;


/** Javadoc for class. */
public class TestBug {}

(Notice the two consecutive empty lines between package com.example; and /** Javadoc for class. */.)

Expected Output

package com.example;

/** Javadoc for class. */
public class TestBug {}

Additional Context & Workaround

• Second Pass Result: Executing google-java-format a second time on the first pass output (google-java-format TestBug.java | google-java-format -) produces the correct output with a single blank line.

主要言語
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 を短くまとめたダイジェスト。