Title: unused import removal leaves extra blank line between package declaration and class Javadoc / declaration · Issue #1436 · google/google-java-format · GitHub
Open Graph Title: unused import removal leaves extra blank line between package declaration and class Javadoc / declaration · Issue #1436 · google/google-java-format
X Title: unused import removal leaves extra blank line between package declaration and class Javadoc / declaration · Issue #1436 · google/google-java-format
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...
Open Graph 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 for...
X 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 for...
Opengraph URL: https://github.com/google/google-java-format/issues/1436
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unused import removal leaves extra blank line between package declaration and class Javadoc / declaration","articleBody":" 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). \n \nRunning `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 \n \n## Environment \n * **`google-java-format` Version:** Tested on `1.25.2` through `1.35.0` (including recent builds). \n* **Operating System:** Linux / macOS / Cross-platform \n \n## Minimal Reproducible Example \n \n### Input Code (`TestBug.java`) \n \n ```java \n package com.example; \n\n import static io.grpc.MethodDescriptor.generateFullMethodName;\n\n /**\n * Javadoc for class.\n */\n public class TestBug {\n }\n\n### Command Executed\n\n google-java-format TestBug.java\n\n## Actual Output (First Pass)\n\n package com.example;\n\n\n /** Javadoc for class. */\n public class TestBug {}\n\n (Notice the two consecutive empty lines between package com.example; and /** Javadoc for class. */.)\n\n ## Expected Output\n\n package com.example;\n\n /** Javadoc for class. */\n public class TestBug {}\n\n ## Additional Context & Workaround\n\n • 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.\n","author":{"url":"https://github.com/zhumin8","@type":"Person","name":"zhumin8"},"datePublished":"2026-08-04T02:26:00Z","url":"https://github.com/google/google-java-format/issues/1436"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:942e4cc9-e70f-3323-e966-ffbcfe77b484 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A748:54397:23AC11:308E01:6AFBAF77 |
| html-safe-nonce | 53b680a4375b6b24cd9b5309623312fe1b94a4a0d737d3721ab55dcd8fca7460 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzQ4OjU0Mzk3OjIzQUMxMTozMDhFMDE6NkFGQkFGNzciLCJ2aXNpdG9yX2lkIjoiNzI4NDExOTkxNTY3MjA4ODQzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 19462ce9941dad0d8b89ef355e920e0602c38a0dda64e25a12ecf1131ed71eaf |
| hovercard-subject-tag | issue:5056019109 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/google/google-java-format/1436/issue_layout |
| twitter:image | https://opengraph.githubassets.com/63634424cc0977315509ded5505308543ca8e62f90d0abe521447840dfc13a35/google/google-java-format/issues/1436 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/63634424cc0977315509ded5505308543ca8e62f90d0abe521447840dfc13a35/google/google-java-format/issues/1436 |
| og:image:alt | 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 for... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zhumin8 |
| hostname | github.com |
| expected-hostname | github.com |
| None | e25fbd830d3e6ad0e8935c105cf4fdc70c593dffcd27bb45b790ae4fece5ea55 |
| turbo-cache-control | no-preview |
| go-import | github.com/google/google-java-format git https://github.com/google/google-java-format.git |
| octolytics-dimension-user_id | 1342004 |
| octolytics-dimension-user_login | |
| octolytics-dimension-repository_id | 35448780 |
| octolytics-dimension-repository_nwo | google/google-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 35448780 |
| octolytics-dimension-repository_network_root_nwo | google/google-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 08c8f17f9d27054a108b8b6254e405de0151f660 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width