openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
27 stars 43 forks source link

DefaultComesLast recipe creates duplicate case #289

Open delanym opened 1 month ago

delanym commented 1 month ago

If default comes before a case and simply continues into that case

      default:
      case DERIVATION_MODE:
        System.out.println("default");
        break;

refactoring with org.openrewrite.staticanalysis.DefaultComesLast from org.openrewrite.recipe:rewrite-static-analysis:1.6.0 results in a duplicate case and code duplication

      case DERIVATION_MODE:
        System.out.println("default");
        break;
      case DERIVATION_MODE:
      default:
        System.out.println("default");
timtebeek commented 1 month ago

That's unfortunate and definitely something to fix; thanks for the clear example! Is this something you'd be looking to help fix?

delanym commented 1 month ago

I can't promise anything - we've just migrated JDK from 11 to 21 so my hands are full. I guess its always like that though. What I feel compelled to do is write the ticket.

timtebeek commented 1 month ago

Logging the issue is much appreciated, and understandable that you have other things to get to as well. Just good to know what to expect such that there's at least no duplicated efforts. Keep em coming! :)

nbenjamin commented 1 month ago

Hi @timtebeek , I have created a PR to address this issue and added the testcase. could you please review this