-
Notifications
You must be signed in to change notification settings - Fork 727
SONARJAVA-6358 Implement quickfix for S8688 #5612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,4 +30,5 @@ void test() { | |
| .withCheck(new NowWithoutParametersCheck()) | ||
| .verifyIssues(); | ||
|
Comment on lines
30
to
31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The quickfix annotations in the sample file (
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quickfix inserts
ZoneId.systemDefault()as a literal string but never addsimport java.time.ZoneId;. Users whose file doesn't already importZoneIdwill get non-compiling code after applying the fix.The test passes today only because
NowWithoutParametersCheckSample.javahappens to importZoneIdalready (line 13). A new quickfix-specific test file without that import would surface this failure.The established pattern in this codebase uses
QuickFixHelper.newImportSupplierto conditionally inject the import. SeeReturnEmptyArrayNotNullCheck(lines 45, 178–182) for the reference implementation. The fix here requires:QuickFixHelper.ImportSupplier importSupplierfield (lazily initialised, reset inscanFile).context) intocomputeQuickFixso it can callimportSupplier.newImportEdit("java.time.ZoneId").ifPresent(builder::addTextEdit).