unused import removal leaves extra blank line between package declaration and class Javadoc / declaration
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
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-formatVersion: Tested on1.25.2through1.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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/google-java-format
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google/google-java-format#1094 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
google/google-java-format#1450 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
google/google-java-format#1439 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
google/google-java-format#1428 · 3 comments ·
-
Eclipse
Difficulty 3/5 1-2 days Newbie friendliness 55/100
google/google-java-format#1417 ·
All issues in google/google-java-format
Similar issues
-
bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
opensearch-project/ml-commons#5094 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
emitter:client:csharp feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Openbug frontend maui-pilot
Difficulty 2/5 1-3 hours Newbie friendliness 72/100