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

Drop unused DiffNotApplicableException #4086

Conversation

Stephan202
Copy link
Contributor

This exception type was introduced along with Refaster in
01f7136, but no instance is ever
instantiated.

This exception type was introduced along with Refaster in
01f7136, but no instance is ever
instantiated.
Copy link
Contributor Author

@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.

I noticed this while working on #4085. It could of course be that some Google-internal code does reference this type, in which case this PR may not make sense or require significant modification.

@@ -123,7 +123,7 @@ public void run() {
if (completed % 100 == 0) {
logger.log(Level.INFO, String.format("Completed %d files in %s", completed, stopwatch));
}
} catch (IOException | DiffNotApplicableException e) {
} catch (IOException e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which raises the question: was the following perhaps intended?

Suggested change
} catch (IOException e) {
} catch (IOException | RuntimeException e) {

(But if after all those years the current code sufficed... 🤷)

@cushon
Copy link
Collaborator

cushon commented Sep 13, 2023

I noticed this while working on #4085. It could of course be that some Google-internal code does reference this type, in which case this PR may not make sense or require significant modification.

That is unfortunately the case, but I will take a closer look at whether the single place that's instantiating this exception type still makes sense

@cushon
Copy link
Collaborator

cushon commented Sep 19, 2023

I noticed this while working on #4085. It could of course be that some Google-internal code does reference this type, in which case this PR may not make sense or require significant modification.

That is unfortunately the case, but I will take a closer look at whether the single place that's instantiating this exception type still makes sense

We have a another Diff implementation for uninteresting historical reasons, and it tries to handle invalid replacements (e.g. that offsets outside the file) and throw DiffNotApplicableException. The goal is to be able to apply a collection of fixes and skip any invalid ones, but still apply the valid ones.

I don't have strong opinions about this :) I think we could either

@Stephan202
Copy link
Contributor Author

Interesting! I don't immediately have a strong opinion either. Some initial thoughts:

  • Going for option (1) would likely be easier to do if the other diff logic is open-source/included, so that the requisite changes can be tested more easily.
  • On the other hand, one could argue that in case of invalid replacements, the proper thing to do is to fix the check that emits these invalid replacements. 😅
    • This stance assumes that the suggested fixes aren't made invalid by other changes, but IIUC, as long as all suggested fixes are applied in one go, that shouldn't be an issue.
    • (It is true that occasionally emitting the right fix can be tricky, because the AST-source correspondence isn't perfect. But so far I've found that a solution always exists.)

So all-in-all I'm tending to "let's keep it simple" and go for option (2), but that does assume of course that the Google-internal diff is no longer relied upon.

: Distantly related here is #4088, but as far as I can tell the general case of chaining dependent bug checkers will always require an intermediate compilation phase, in which case there's no reason to assume that the replacements emitted by each round can't be accurate, relative to the source code produced by the previous round.

@cushon
Copy link
Collaborator

cushon commented Sep 20, 2023

Thanks for thinking this through! I am leaning towards (2).

one could argue that in case of invalid replacements, the proper thing to do is to fix the check that emits these invalid replacements.

I think that is an extremely valid argument :) I think the motivation might have been for iterating on new checks, where it's useful to apply the fixes we can even if some of them are bogus. We'd also want to fix the bad findings, but it takes some time to run the check across the depot, and being able to apply a subset of the fixes in that case cuts down on the number of iterations. But (2) is still fine for that.

copybara-service bot pushed a commit that referenced this pull request Sep 21, 2023
Let any IndexOutOfBoundsExceptions propagate, and handle RuntimeException in
DiffApplier.

See discussion in #4086.

PiperOrigin-RevId: 566971731
copybara-service bot pushed a commit that referenced this pull request Sep 21, 2023
Let any IndexOutOfBoundsExceptions propagate, and handle RuntimeException in
DiffApplier.

See discussion in #4086.

PiperOrigin-RevId: 566971731
copybara-service bot pushed a commit that referenced this pull request Sep 21, 2023
Let any IndexOutOfBoundsExceptions propagate, and handle RuntimeException in
DiffApplier.

See discussion in #4086.

PiperOrigin-RevId: 567323714
@cushon
Copy link
Collaborator

cushon commented Sep 21, 2023

DiffNotApplicableException has been removed in 737dec0. Thanks for pointing this out!

@cushon cushon closed this Sep 21, 2023
@Stephan202 Stephan202 deleted the sschroevers/drop-unused-DiffNotApplicableException branch September 21, 2023 18:21
@jeandersonbc
Copy link

but as far as I can tell the general case of chaining dependent bug checkers will always require an intermediate compilation phase

Thanks for the input @Stephan202!

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.

3 participants