ChrisK
ChrisK

Reputation: 158

Eclipse flags a piece of code with a 'Dead code' warning. Why in this case?

I know that there are a few examples of 'random dead code warning' in Eclipse.

But specifically for my case, I want to find out whether this is also a 'false positive' or whether I am too tired to understand what is going on...

    @Override
    public int getNumUnappendedCol() {

        return appendIndex == -1 ? getNumCol() : appendIndex; 
    }

This ternary statement is being flagged, specifically the condition and appendIndex. As I understand it (not my code), this is supposed to return appendIndex if it is not equal to -1. Otherwise return the value obtained from getNumCol().

Am I missing something or should I just ignore Eclipse? I regularly refresh/ clean/ build the project so that wouldn't solve the issue.

Upvotes: 0

Views: 83

Answers (1)

ChrisK
ChrisK

Reputation: 158

The problem ended up being a final declaration of appendIndex which was initialized to -1, so the ternary statement could never even access the false option.

Upvotes: 1

Related Questions