vendredi 20 avril 2018

The corresponding then clause does not complete normally

Given a simple if statment in the form

public static String test(boolean flag) {
    if (!flag) {
        return "no";
    } else {
        System.out.println("flag enabled");
    }
    return "yes";
}

Eclipse gives me the warning, underlining the whole else block

Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally

this question seems related, but I'm not using return in the else, and else is not finally.

I understand that this is simply a preference, and that it can be turned off. However, I don't like ignoring things simply because I don't understand why it is a problem. And I can't seem to find any documentation on why Eclipse added this as a configurable warning.

So in all, What does "The corresponding then clause does not complete normally" mean? Does this affect code execution, or is it simply a formatting preference? If this isn't just a cosmetic issue, than what are the risk/side effects?

Aucun commentaire:

Enregistrer un commentaire