You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recipe FallThrough: A switch inside a switch incorrectly handled. Results in non compilable code. #173
We have a few classes which contain a switch inside a switch. Even 3+ levels deep. Recipe FallThrough does not seem to be able to handle this correctly - all the time??. It breaks at least for the example beneath. Two break statements are added by it. The first one results in the IDE in ' unreachable statement'. When compiling I get two errors: First ' unreachable statement' and ' missing return statement' on the closing } char of the method.
The problem here is that the logic which checks if the block in a switch case completes normally or not doesn't consider all cases. A switch statement which in all its cases does a return is one such example. I think there are probably others which are currently not caught by the recipe. While for example while (true) return; and try { return; } finally {} should be considered such cases, if (true) return; should not. This type of checking is probably not that uncommon. We should introduce a utility which recipes can use for this purpose.
Activity
knutwannheden commentedon Apr 3, 2023
The problem here is that the logic which checks if the block in a switch case completes normally or not doesn't consider all cases. A switch statement which in all its cases does a return is one such example. I think there are probably others which are currently not caught by the recipe. While for example
while (true) return;andtry { return; } finally {}should be considered such cases,if (true) return;should not. This type of checking is probably not that uncommon. We should introduce a utility which recipes can use for this purpose.timtebeek commentedon Sep 26, 2023
Cross referencing
jbessels commentedon Oct 19, 2023
I've retested the recipe. It works!!
Now no changes are made to the 7 files I had to use tags for.
Thanks a lot
FallThrough handles switch in switch (fixes openrewrite#173)