Problem
Describe the issue you are experiencing.
Expected behavior
Describe what you expected to see.
Example diff
From: zuul-core/src/main/java/com/netflix/netty/common/metrics/Http2MetricsChannelHandlers.java
protected void incrementCounter(Registry registry, String counterName, String metricId, Http2Frame frame) {
long errorCode;
- if (frame instanceof Http2ResetFrame resetFrame) {
- errorCode = resetFrame.errorCode();
- } else if (frame instanceof Http2GoAwayFrame goAwayFrame) {
- errorCode = goAwayFrame.errorCode();
- } else {
- errorCode = -1;
+ switch (frame) {
+ caseHttp2ResetFrame resetFrame -> errorCode = resetFrame.errorCode();
+ caseHttp2GoAwayFrame goAwayFrame -> errorCode = goAwayFrame.errorCode();
+ case null -> errorCode = -1;
}
registry.counter(counterName, "id", metricId, "frame", frame.name(), "error_code", Long.toString(errorCode))
Recipes in example diff:
org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitch
org.openrewrite.java.migrate.UpgradeJavaVersion
References:
- View original result
- Recipe ID:
org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitch
- Recipe Name:
If-else-if-else to switch
- Repository:
Netflix/zuul/master
- Created at Wed Apr 22 2026 22:15:03 GMT+0200 (Central European Summer Time)
Problem
Expected behavior
Example diff
From:
zuul-core/src/main/java/com/netflix/netty/common/metrics/Http2MetricsChannelHandlers.javaprotected void incrementCounter(Registry registry, String counterName, String metricId, Http2Frame frame) { long errorCode; - if (frame instanceof Http2ResetFrame resetFrame) { - errorCode = resetFrame.errorCode(); - } else if (frame instanceof Http2GoAwayFrame goAwayFrame) { - errorCode = goAwayFrame.errorCode(); - } else { - errorCode = -1; + switch (frame) { + caseHttp2ResetFrame resetFrame -> errorCode = resetFrame.errorCode(); + caseHttp2GoAwayFrame goAwayFrame -> errorCode = goAwayFrame.errorCode(); + case null -> errorCode = -1; } registry.counter(counterName, "id", metricId, "frame", frame.name(), "error_code", Long.toString(errorCode))Recipes in example diff:
org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitchorg.openrewrite.java.migrate.UpgradeJavaVersionReferences:
org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitchIf-else-if-else to switchNetflix/zuul/master