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: googleapis/librarian#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.
When
google-java-formatremoves an unused import statement located between apackagedeclaration 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-formata second time on the output collapses the extra blank line as expected. We observed this in generated code, more context here: googleapis/librarian#7146Environment
google-java-formatVersion: Tested on1.25.2through1.35.0(including recent builds).Minimal Reproducible Example
Input Code (
TestBug.java)Command Executed
Actual Output (First Pass)
(Notice the two consecutive empty lines between package com.example; and /** Javadoc for class. */.)
Expected Output
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.