Unchecked warnings are not removed with Javac @SuppressWarnings annotation

975 views Asked by At

I cannot remove my warnings with unchecked cast. I believe this is very strange because I have added the @SuppressWarnings("unchecked") annotation on the method but the Javac still showing the warnings.

[unchecked] unchecked cast (List<Integer>) getObject(LIST);
    return (List<Integer>) getObject(LIST);
    required: List<Integer>
    found:    Object

I have create an Example, It throws 2 warnings. I'm using Oracle JDK 1.7 update 79.

package strange;
import java.util.List;

public class Strange implements Constants {

    //Throw Warning
    @SuppressWarnings("unchecked")
    protected List<Integer> getList() {
        return (List<Integer>) getObject(LIST);
    }

    @SuppressWarnings("unchecked")
    protected List<Integer> getList2() {
        return (List<Integer>) getObject(LIST);
    }

    //Throw Warning
    @SuppressWarnings("unchecked")
    protected List<Integer> getOtherList() {
        return (List<Integer>) getObject(OTHER);
    }

    protected Object getObject(String key) {
        return new Object();
    }
}

interface Constants {

    public static final String LIST = "list";
    public static final String OTHER = "other";
}

Thanks.

1

There are 1 answers

0
aioobe On BEST ANSWER

This looks like a javac bug. It doesn't reproduce in 1.8.0u45 though.

Did a quick search and it could be related to for instance JDK-8016099 or JDK-8022144. One could do a hg bisect to find the exact changeset that resolved the issue.

Possibly related: