@SuppressWarning doesn't suppress the warning for invoking method

Сергей Цыпанов sergei.tsypanov at yandex.ru
Mon Dec 21 10:10:27 UTC 2020


I've created a PR https://github.com/openjdk/jdk/pull/1764 to solve JDK-8193031. Originally I haven't put @SuppressWarnings("varargs") over the method as the body only contains the invocation of Arrays.asList() which is already annotated with @SuppressWarnings("varargs").

The build however failed with error

src/java.base/share/classes/java/util/Collections.java:5590: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter elements
        return c.addAll(Arrays.asList(elements));
error: warnings found and -Werror specified
1 error

As it appears from the documentation of SaveVarargs:

> Compilers are encouraged to issue warnings when this annotation type is applied to a method or constructor declaration where:

> The body of the method or constructor declaration performs potentially unsafe operations, such as an assignment to an element of the variable arity parameter's array that generates an unchecked warning.

But as soon as Arrays.asList already suppresses the warning I expect the compilation be ok, but it fails. So my question is simple: is it a bug in compiler or not?

Sergey Tsypanov

More information about the compiler-dev mailing list