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
Applying the code clean up "Convert if/else if/else chain with 3 blocks min to switch" produces the following code
publicclassDummy {
enumTestEnum {
A, B, C
}
publicintdoSomething(finalTestEnumval) {
switch ( val ) {
caseTestEnum.A:
return1;
caseTestEnum.B:
return2;
caseTestEnum.C:
return3;
default:
break;
}
return4;
}
}
The cleaned up code now throws a NullPointerException, when being called with null, instead of falling through to return 4;.
I guess in case null was not explicitly treated in the original code, then the correct clean up would be to use case null, default: instead of default:.
The text was updated successfully, but these errors were encountered:
- for < JVM 21 add an if/else that checks for null
- for JVM 21 and up, add case null
- modified SwitchFixCore and modified tests in CleanUpTest12
to also not qualify enums if the switch value is an enum
- fixeseclipse-jdt#1714
- for < JVM 21 add an if/else that checks for null
- for JVM 21 and up, add case null
- modified SwitchFixCore and modified tests in CleanUpTest12
to also not qualify enums if the switch value is an enum
- fixes#1714
BTW: thanks @FlorianKroiss for reporting this. The cleanup has been changed to add the case null when the Java version allows it and to create an if statement otherwise.
Consider the following example:
Calling this method with
null
returns 4.Applying the code clean up "Convert if/else if/else chain with 3 blocks min to switch" produces the following code
The cleaned up code now throws a
NullPointerException
, when being called withnull
, instead of falling through toreturn 4;
.I guess in case
null
was not explicitly treated in the original code, then the correct clean up would be to usecase null, default:
instead ofdefault:
.The text was updated successfully, but these errors were encountered: