[DeadCode] Skip dead catch before catch-all Throwable/Exception in RemoveDeadCatchRector - #8462
Merged
Merged
Conversation
…moveDeadCatchRector A catch block that only re-throws its own exception is not dead when a later catch of Throwable or Exception handles it differently. As those types catch anything, the current catch type cannot always be resolved to prove the parent relation, so treat them as catch-all explicitly. Fixes #9888 Claude-Session: https://claude.ai/code/session_011TpTyRop7qReoHY1MfLpqF
…emoveDeadCatchRector An unresolvable next catch type may be a parent of the current caught exception, so removing the re-throwing catch could change behavior by routing the exception to a different handler. Claude-Session: https://claude.ai/code/session_01Bh57AAY3DpLKXGX5c7EETM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9888
A catch block that only re-throws its own exception is not dead when a later catch of
ThrowableorExceptionhandles the same exception differently. Removing it would let the exception fall through to the catch-all block and change behavior.Because
Throwable/Exceptioncatch anything, the current catch type often cannot be resolved to prove the parent relation (e.g. a third-partyValidationExceptionunknown to reflection). The rule now treats those two types as catch-all explicitly, so the preceding re-throw catch is kept.Before (wrongly removed):
Added
skip_dead_catch_before_catch_all_exceptionfixture covering the case.https://claude.ai/code/session_011TpTyRop7qReoHY1MfLpqF