I have a bit of a complex validation system, that simplified looks something like the following:
private static void mainMethod(@Nullable String startParam, @Nullable String nextParam) {
String nextStep = methodSelect(startParam, nextParam);
switch (nextStep) {
case "none":
break;
case "goFinal":
finalMethod(startParam);
break;
case "goNext":
nextMethod(nextParam);
break;
}
}
private static void nextMethod(@NotNull String nextParam) {
System.out.println(nextParam);
}
private static void finalMethod(@NotNull String startParam) {
System.out.println(startParam);
}
@NotNull
private static String methodSelect(@Nullable String startParam,@Nullable String nextParam) {
if (startParam == null && nextParam == null) {
return "none";
} if (startParam == null) {
return "goNext";
} else {
return "goFinal";
}
}
But I get warnings when in the switch statement calling both finalMethod() and nextMethod() about "Argument x might be null", even though methodSelect() and the switch statement afterwards makes sure that these arguments will not be null. How do I correctly get rid of these warnings, hopefully without having another check for null in or before these methods? Thanks!
I'm using IntelliJ IDEA 2016.3.4, Java 8, and annotations:
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;