Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dead code warning?

Why am I getting a dead code warning on the i++ in this function ?

InputFilter hexInputFilter()
    {
    return new InputFilter()
        {
            @Override
            public CharSequence filter(CharSequence source, int start,
                    int end, Spanned dest, int dstart, int dend)
                {
                for (int i = start; i < end; i++)
                    {
                    if ((source.charAt(i) >= '0')
                            && (source.charAt(i) <= '9'))
                        {
                        return null;
                        }
                    if ((Character.toUpperCase(source.charAt(i)) >= 'A')
                            && (Character.toUpperCase(source.charAt(i)) <= 'F'))
                        {
                        return null;
                        }
                    return "";
                    }
                return null;
                }
        };
    }
like image 312
Regis St-Gelais Avatar asked Sep 09 '25 15:09

Regis St-Gelais


1 Answers

There's no chance for the for to loop more than once because you are returning:

return "";

Thus, i++ won't be executed ever and that's why you get a dead code warning. Maybe you want to remove that return ""; and/or put it outside the for.

like image 134
Cristian Avatar answered Sep 12 '25 05:09

Cristian