René's URL Explorer Experiment


Title: Keep java.lang imports that disambiguate a simple name by abashev · Pull Request #174 · openjavaformat/open-java-format · GitHub

Open Graph Title: Keep java.lang imports that disambiguate a simple name by abashev · Pull Request #174 · openjavaformat/open-java-format

X Title: Keep java.lang imports that disambiguate a simple name by abashev · Pull Request #174 · openjavaformat/open-java-format

Description: Fixes #149. What was wrong Removing unused imports dropped every import from java.lang, used or not. A single-type import shadows a type with the same simple name declared in the file's own package, and one brought in by an import on demand (JLS 6.4.1). So a used import java.lang.Byte; can be the only thing that binds Byte to the JDK class, and removing it makes the name ambiguous or binds it to the other class: package com.company.project.bar; import com.company.project.foo.*; // also declares a Byte import java.lang.Byte; public class Test { Byte foo() { return null; } } Until now the java.lang.Byte import was removed. I checked this with a com.company.project.foo.Byte class next to the file: the input compiles, but the output of 21.X.X fails with reference to Byte is ambiguous. Now the import stays, because Byte is used. Unused java.lang imports and import java.lang.*; are still removed, and so are imports from the file's own package, which can never disambiguate anything. The change The commit is palantir#1778 by Zayan Khan, cherry-picked with -x (c9d7b75), with the author and the message kept. Upstream closed the PR unmerged; it fixes palantir#1334. Its CLAUDE.md and changelog commits are left out. The only conflict was in RemoveUnusedImportsTest, whose table has more rows here; upstream's rows come after ours. Tests The first commit adds upstream's five rows to RemoveUnusedImportsTest and changes the existing row whose output now keeps import java.lang.Foo;. The second commit is ours. It moves the tests of unused import removal into case files under test-cases/imports/, one file per test, named after what it checks: 19 of the table's 23 rows and the one test of RemoveUnusedImportsCaseLabelsTest became cases. A case runs the whole formatter, so its after block is the row's expected output, formatted. Four rows stay in RemoveUnusedImportsTest as plain tests with text blocks: The three rows of #37. A case fixes the imports before it formats, and formatting removes a doubled blank line by itself, so those cases would pass without the code they test. The command line formats first. The module import. It parses only from JDK 23 on, and the cases run on JDK 21 as well. With the RemoveUnusedImports of 21.X.X, four cases fail: each loses a java.lang import it uses. With the fix all of them pass. FormatterCasesTest: 887 → 907 RemoveUnusedImportsTest: 18 → 4 (the module import is skipped on JDK 21; on JDK 25 all four run) RemoveUnusedImportsCaseLabelsTest: removed, its test is now a case open-java-format: 1408 → 1413 tests ./gradlew test --rerun passes for all modules (Gradle plugin 51, IntelliJ plugin 10), and the 907 cases also pass on JDK 25 Effect on output Of the 15,747 files of the JDK 21 sources, 13 format differently. Each of them keeps a java.lang import that it uses (String, Integer, Character, RuntimePermission and others), and a second run changes none of them. In two of these files a comment that belongs to such an import no longer ends up somewhere else: // java import // +import java.lang.Comparable; // to be substituted for jdk1.1.x import java.util.Set; -// to be substituted for jdk1.1.x That is javax/management/openmbean/OpenMBeanParameterInfo.java. In java/util/prefs/Preferences.java, the comment // These imports needed only as a workaround for a JavaDoc bug stays with its import, where before it was left alone after the import block. Because this changes output, it counts toward the second number of the version.

Open Graph Description: Fixes #149. What was wrong Removing unused imports dropped every import from java.lang, used or not. A single-type import shadows a type with the same simple name declared in the file's own pac...

X Description: Fixes #149. What was wrong Removing unused imports dropped every import from java.lang, used or not. A single-type import shadows a type with the same simple name declared in the file's own...

Opengraph URL: https://github.com/openjavaformat/open-java-format/pull/174

X: @github

direct link

Domain: redirect.github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:e2b87c5f-ea28-debc-ef4b-72718093ccdf
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9546:202797:102DA7:165637:6AFBCB06
html-safe-nonce9415e1f10f63dc3c8a0143c4e4e0d858185b89e1d39f8fa9ef2db63d70a24dd4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTQ2OjIwMjc5NzoxMDJEQTc6MTY1NjM3OjZBRkJDQjA2IiwidmlzaXRvcl9pZCI6IjczMTAyODczNDMyMjUzOTE4NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca0cb58422d4a7e388ae76d478ad42982a9bdb2704a357ccefb7cfc99493da3c9
hovercard-subject-tagpull_request:5082911374
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/openjavaformat/open-java-format/pull/174/files
twitter:imagehttps://avatars.githubusercontent.com/u/214171?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/214171?s=400&v=4
og:image:altFixes #149. What was wrong Removing unused imports dropped every import from java.lang, used or not. A single-type import shadows a type with the same simple name declared in the file's own pac...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None18742cb872ec73544356e60359266b67aafece70c4ce008042e06227924cdd07
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git
octolytics-dimension-user_id325177626
octolytics-dimension-user_loginopenjavaformat
octolytics-dimension-repository_id1288055459
octolytics-dimension-repository_nwoopenjavaformat/open-java-format
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forktrue
octolytics-dimension-repository_parent_id214273098
octolytics-dimension-repository_parent_nwopalantir/palantir-java-format
octolytics-dimension-repository_network_root_id214273098
octolytics-dimension-repository_network_root_nwopalantir/palantir-java-format
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release820be804f18e1ef3940bd74a00d41d73d02e2b91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files#start-of-content
https://redirect.github.com/
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F174%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F174%2Ffiles
Sign uphttps://redirect.github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=openjavaformat%2Fopen-java-format
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
openjavaformathttps://redirect.github.com/openjavaformat
open-java-formathttps://redirect.github.com/openjavaformat/open-java-format
Codehttps://redirect.github.com/openjavaformat/open-java-format
Issues30 (30)https://redirect.github.com/openjavaformat/open-java-format/issues
Pull requests5 (5)https://redirect.github.com/openjavaformat/open-java-format/pulls
Discussionshttps://redirect.github.com/openjavaformat/open-java-format/discussions
Actionshttps://redirect.github.com/openjavaformat/open-java-format/actions
Security and qualityhttps://redirect.github.com/openjavaformat/open-java-format/security
Insightshttps://redirect.github.com/openjavaformat/open-java-format/pulse
Sign up for GitHub https://redirect.github.com/signup?return_to=%2Fopenjavaformat%2Fopen-java-format%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://redirect.github.com/login?return_to=%2Fopenjavaformat%2Fopen-java-format%2Fissues%2Fnew%2Fchoose
abashevhttps://redirect.github.com/abashev
21.X.Xhttps://redirect.github.com/openjavaformat/open-java-format/tree/21.X.X
fix/keep-used-java-lang-importhttps://redirect.github.com/openjavaformat/open-java-format/tree/fix/keep-used-java-lang-import
Conversation 0 https://redirect.github.com/openjavaformat/open-java-format/pull/174
Commits 2 https://redirect.github.com/openjavaformat/open-java-format/pull/174/commits
Checks 17 https://redirect.github.com/openjavaformat/open-java-format/pull/174/checks
Files changed https://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Keep java.lang imports that disambiguate a simple name https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#top
Show all changes 2 commits https://redirect.github.com/openjavaformat/open-java-format/pull/174/files
bff74a0 Keep java.lang imports that disambiguate a simple name ZayanKhan-12 Sep 15, 2026 https://redirect.github.com/openjavaformat/open-java-format/pull/174/commits/bff74a00cf54e5c45d93ad9ef076e514c82277a1
e66ee55 Move the tests of unused import removal into case files abashev Oct 30, 2026 https://redirect.github.com/openjavaformat/open-java-format/pull/174/commits/e66ee55fd7ea0fa67ce20a2711c2ad830e059f71
Clear filters https://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
RemoveUnusedImports.java https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-5299716450ca7354169f28803b5295a125ab25fdfbd3257eba438d4ff4f91768
RemoveUnusedImportsCaseLabelsTest.java https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-3cbe6525ef6fd3ac615c28684a0f928f50cacdc1787afb35c61789a6e430d917
RemoveUnusedImportsTest.java https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-e560a53ebc61bb106744b2431ebabab2a17823a75d2611eafd5acfd54b25a035
fullyQualifiedJavadocReferenceNeedsNoImport.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-2cc2f06b6e1668304a987b939f1dae4e802e669d0b08a6675e9c5fe9744f4597
importOnDemandStays.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-8eed029e3de49495bbbbf28be46694eebd6ce1bc521cf0b8bf49894bf5fb899b
importUsedOnlyByAJavadocLinkStays.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-a99cedc3d4c777ae770fab3bf4f49ca8f995bef0dd85856bd9d22f3c47a34844
importsFromTheOwnPackageGo.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-6e323d453555c66be8369b09024551d9ba9dd6a290ff653c8167db73a4b2fe63
importsUsedByJavadocMemberReferencesStay.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-105ee0716ad98579bcf8c69acde326f8c9b2d82bc919b65ad21158300d60b058
javaLangImportOnDemandGoes.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-3e01e40c70b7218b9a1b36d7c0f5e3d5950ad44f1e906dc0683308b9fe0c6cb4
javaLangImportUsedByJavadocStays.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-b03d304f612eac2f4fe081bf3a78b6c57085ff2120c36fffb67edd8cd87af4fa
javadocArrayParameterKeepsTheImportOfItsQualifier.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-afed97974659fd3a61386cdd8a7771796c110d4f94269d6c09d72e84abe0ba89
javadocLinkOnALaterLineKeepsItsImport.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-448a1d12c631534bb17652b003a448365fdebaf2a2ef53d1a8d43a58b6148702
javadocReferenceToANestedTypeKeepsTheOuterImport.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-202baa2e19a127c929a53fcbc57c3a2ec7d945d697e12cb55f83c5a084970b47
javadocReferenceToOwnMemberWithoutImports.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-eb8ccb5afc783f52365746ec802159b84daaa299e30e5e6b925fa8629c3c1ad5
javadocTagsKeepTheirImports.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-5f789ec5ce826b912156164b9ba07c7a7c6824c24127e034c0df757b2b954426
typesInCaseLabelsKeepTheirImports.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-a8e6f6e9edfb8da0468340a449d894ce8e98d9990b5a7d04d20d2f06822a67d6
unusedImportGoesFromBesideAUsedOne.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-3a3d96f211e351ed58b7c757d2b1ecee4c86c5561f40780911b457e4e307deb8
unusedImportsOnTheLineOfAUsedOneGo.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-77197633393559f8d19d6de5364d62c2f0c1901fdb7f3553cab0cf37cb50daec
unusedJavaLangImportGoes.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-802b492d4232b1b0ab1606c23a3b688358d2f41e8514d120b9609c78e21e80cf
unusedJavaLangImportGoesBesideAnImportOnDemand.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-a01b885fee5e9098edd0d7fe19779c43ec3c7c8afee1925e20155c0c7ec45167
usedJavaLangImportShadowsATypeOfTheOwnPackage.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-3afd197ba1d48cbeaff7e4a3dddb42d394a7e9c8b872af4c07e08e01014ce8ea
usedJavaLangImportShadowsAnImportOnDemand.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-86b71b5b5f7b3722070065d4d4d74adf5c3d5e2218b04446de7dd7ce7c6fa882
usedJavaLangImportStaysOwnPackageImportGoes.case https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-00fe88d78345347f133235c3983f1eab314220e6b0761a40098208b2411545b0
open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.javahttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-5299716450ca7354169f28803b5295a125ab25fdfbd3257eba438d4ff4f91768
View file https://redirect.github.com/openjavaformat/open-java-format/blob/e66ee55fd7ea0fa67ce20a2711c2ad830e059f71/open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/174/{{ revealButtonHref }}
https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-5299716450ca7354169f28803b5295a125ab25fdfbd3257eba438d4ff4f91768
https://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-5299716450ca7354169f28803b5295a125ab25fdfbd3257eba438d4ff4f91768
...-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.javahttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files#diff-3cbe6525ef6fd3ac615c28684a0f928f50cacdc1787afb35c61789a6e430d917
View file https://redirect.github.com/openjavaformat/open-java-format/blob/6bcacfc3aee4854dc7ca4799c700bb6f4f3d3ef4/open-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.java
Open in desktop https://desktop.github.com
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/174/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.