Skip to content
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

Ignore disabled checks passed to -XepPatchChecks #4028

Conversation

oxkitsune
Copy link
Contributor

Rather than throwing an NoSuchElementException.

Fixes #3908.

@google-cla
Copy link

google-cla bot commented Jul 31, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oxkitsune these PRs are generally merged with the PR text as commit message, so I would also add this sentence to the PR body (just like in the commit message):

Rather than throwing an NoSuchElementException.

@rickie
Copy link
Contributor

rickie commented Jul 31, 2023

@oxkitsune these PRs are generally merged with the PR text as commit message, so I would also add this sentence to the PR body (just like in the commit message):

That's already the case right? It should be good like it is right now.

@Stephan202
Copy link
Contributor

I would swear that my browser didn't show it. But I must have been confused. 🤔

copybara-service bot pushed a commit that referenced this pull request Jul 31, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 552531114
copybara-service bot pushed a commit that referenced this pull request Jul 31, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 552531114
copybara-service bot pushed a commit that referenced this pull request Sep 7, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563489997
@cushon
Copy link
Collaborator

cushon commented Sep 7, 2023

Thanks for this fix!

I finally did some internal testing of this, and one thing I encountered is that this changes of behaviour of things like -Xep:DeadException:WARN -XepPatchChecks:GetClassOnClass--previously refactorings weren't emitted for DeadException even though it was explicitly enabled, because it wasn't listed in -XepPatchChecks. With this change refactorings are emitted for DeadException.

Do you have thoughts on what the least surprising behaviour here would be?

Copy link
Collaborator

@cushon cushon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un-approving until the question in #4028 (comment) is resolved

@oxkitsune
Copy link
Contributor Author

oxkitsune commented Sep 8, 2023

Do you have thoughts on what the least surprising behaviour here would be?

Personally I think it would make the most sense, if checks passed to -Xep:PatchChecks are the only checks emitting patches, unless they're explicitly disabled.

E.g.

-Xep:DeadException:WARN -XepPatchChecks:GetClassOnClass

would emit patches for GetClassOnClass, and warnings for DeadException.

-Xep:DeadException:OFF -XepPatchChecks:GetClassOnClass,DeadException

would emit just patches for GetClassOnClass

copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
@cushon
Copy link
Collaborator

cushon commented Sep 8, 2023

Do you have thoughts on what the least surprising behaviour here would be?

Personally I think it would make the most sense, if checks passed to -Xep:PatchChecks are the only checks emitting patches, unless they're explicitly disabled.

E.g.

-Xep:DeadException:WARN -XepPatchChecks:GetClassOnClass

would emit patches for GetClassOnClass, and warnings for DeadException.

-Xep:DeadException:OFF -XepPatchChecks:GetClassOnClass,DeadException

would emit just patches for GetClassOnClass

That sounds good to me.

I think that there isn't an order that applyOverrides and filter can be called in that does quite what we want here: calling applyOverrides first causes #3908, and calling filter first causes refactorings to be emitted for checks that are explicitly enabled with -Xep: flags.

I wonder if it makes sense of -XepPatchChecks to just override any -Xep:...:[OFF|WARN|ERROR] flags. That would mean that we went back to the pre-2.19 behaviour where refactorings were emitted for -Xep:CheckName:OFF -XepPatchChecks:CheckName. Would that work for you?

copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 8, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
@Stephan202
Copy link
Contributor

I wonder if it makes sense of -XepPatchChecks to just override any -Xep:...:[OFF|WARN|ERROR] flags. That would mean that we went back to the pre-2.19 behaviour where refactorings were emitted for -Xep:CheckName:OFF -XepPatchChecks:CheckName. Would that work for you?

I'll need to find some time later to think this through more thoroughly, but I wonder whether we'll regret that if #947 is ever merged (still hoping 😉): then -XepPatchChecks: (without further args) would enable patching for all checks, and realistically users will want to apply some exclusions.

That said, we have the #947 change in our fork, and right now we do have this "patch all except those that are OFF" behavior, with a baseline more recent than 2.19.

Easiest is perhaps to first add a few more tests, and then assess impact on #947.

@cushon
Copy link
Collaborator

cushon commented Sep 11, 2023

I'll need to find some time later to think this through more thoroughly

My too, I think :)

The existing logic only calls filter if !namedCheckers.isEmpty(), if we keep that part and do the rest of what I described, I think that would interact well with #947

i.e. something like:

                  ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context);
                  ImmutableSet<String> namedCheckers = epOptions.patchingOptions().namedCheckers();
                  if (!namedCheckers.isEmpty()) {
                    toUse = toUse.filter(bci -> namedCheckers.contains(bci.canonicalName()));
                  } else {
                    toUse = toUse.applyOverrides(epOptions);
                  }
                  return ErrorProneScannerTransformer.create(toUse.get());

Rather than throwing an `NoSuchElementException`.

Fixes google#3908.
@Stephan202
Copy link
Contributor

Rebased this branch to include the changes of #947 (diff applied cleanly; thanks for merging @cushon!), which should make it marginally easier to reason about the solution space. (Actual reasoning still TBD 😅)

copybara-service bot pushed a commit that referenced this pull request Sep 13, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 5865373
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 13, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 5865373
PiperOrigin-RevId: 563488388
copybara-service bot pushed a commit that referenced this pull request Sep 13, 2023
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 5865373
PiperOrigin-RevId: 563488388
@oxkitsune
Copy link
Contributor Author

Hey @cushon apologies for the inactivity 😅
I've just applied the suggestions and I'm happy with this solution!

@cushon
Copy link
Collaborator

cushon commented Mar 4, 2024

Hey @cushon apologies for the inactivity 😅 I've just applied the suggestions and I'm happy with this solution!

No worries, thanks for coming back to this!

copybara-service bot pushed a commit that referenced this pull request Mar 5, 2024
Rather than throwing an `NoSuchElementException`.

Fixes #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 3a75f22
PiperOrigin-RevId: 612947943
@copybara-service copybara-service bot closed this in 9da2d55 Mar 5, 2024
benkard pushed a commit to benkard/jgvariant that referenced this pull request Mar 12, 2024
This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [com.google.errorprone:error_prone_core](https://errorprone.info) ([source](https://github.com/google/error-prone)) |  | minor | `2.25.0` -> `2.26.1` |
| [com.google.errorprone:error_prone_annotations](https://errorprone.info) ([source](https://github.com/google/error-prone)) | compile | minor | `2.25.0` -> `2.26.1` |

---

### Release Notes

<details>
<summary>google/error-prone</summary>

### [`v2.26.1`](https://github.com/google/error-prone/releases/tag/v2.26.1): Error Prone 2.26.1

[Compare Source](google/error-prone@v2.26.0...v2.26.1)

Changes:

-   Fix the module name of the annotations artifact: `com.google.errorprone.annotations` (google/error-prone@9d99ee7)

Full Changelog: google/error-prone@v2.26.0...v2.26.1

### [`v2.26.0`](https://github.com/google/error-prone/releases/tag/v2.26.0): Error Prone 2.26.0

[Compare Source](google/error-prone@v2.25.0...v2.26.0)

Changes:

-   The 'annotations' artifact now includes a `module-info.java` for Java Platform Module System support, thanks to [@&#8203;sgammon](https://github.com/sgammon) in [#&#8203;4311](google/error-prone#4311).
-   Disabled checks passed to `-XepPatchChecks` are now ignored, instead of causing a crash. Thanks to [@&#8203;oxkitsune](https://github.com/oxkitsune) in [#&#8203;4028](google/error-prone#4028).

New checks:

-   [`SystemConsoleNull`](https://errorprone.info/bugpattern/SystemConsoleNull): Null-checking `System.console()` is not a reliable way to detect if the console is connected to a terminal.
-   [`EnumOrdinal`](https://errorprone.info/bugpattern/EnumOrdinal): Discourage uses of `Enum.ordinal()`

Closed issues: [#&#8203;2649](google/error-prone#2649), [#&#8203;3908](google/error-prone#3908), [#&#8203;4028](google/error-prone#4028), [#&#8203;4311](google/error-prone#4311), [#&#8203;4314](google/error-prone#4314)

Full Changelog: google/error-prone@v2.25.0...v2.26.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2.19.x: Exception thrown when a disabled check is passed to -XepPatchChecks
4 participants