Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#1,436 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java
Domain
tooling

Research direction

Start by reproducing the issue with the TestBug.java example and the google-java-format command. Trace the formatting pass that removes the unused import and handles vertical whitespace between the package declaration and class Javadoc. Done means the first formatting pass produces one blank line, matching the expected output, without needing a second pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
6.2k
Forks
936
Avg merge
6m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/google-java-format

All issues in google/google-java-format

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.