Warnings getting past @SuppressWarnings

Jan Lahoda jan.lahoda at oracle.com
Thu Aug 29 11:13:36 PDT 2013


Hi Raluca,

Thanks for the test case - I believe this behavior is a bug. This 
particular usecase was likely fixed by Vicente as bug 8016099:
http://bugs.sun.com/view_bug.do?bug_id=8016099

Sadly, there are a handful of additional usecases where 
@SuppressWarnings does not currently work properly. I am looking into 
these currently.

Thanks for the report,
    Jan

On 08/28/2013 06:08 PM, Raluca Sauciuc wrote:
> Hi compiler-dev,
>
> We ran into an unexpected behavior with javac7 and unchecked warnings.
> Code that compiled without any warnings, by using @SuppressWarnings in a
> few places, has started to display them again.
>
> Here's the simplest example I could find:
>
> public class Test {
>
>   @SuppressWarnings("unchecked")
>   public static <T extends Bar> Foo<T> of(Class<T> type) {
>     return (Foo<T>) cache.get(type);
>   }
>
>   private static final Cache<Class<? extends Bar>,Foo<?>> cache = null;
>
>   interface Cache<K,V> {
>     V get(K key);
>   }
>
>   interface Foo<T extends Bar> {
>     T newFoo(String name);
>   }
>
>   interface Bar { }
> }
>
> $ javac -Xlint:unchecked Test.java
> Test.java:5: warning: [unchecked] unchecked cast
>     return (Foo<T>) cache.get(type);
>                              ^
>   required: Foo<T>
>   found:    Foo<CAP#1>
>   where T is a type-variable:
>     T extends Bar declared in method <T>of(Class<T>)
>   where CAP#1 is a fresh type-variable:
>     CAP#1 extends Bar from capture of ?
> 1 warning
>
> The warning is legitimate, as Cache<Class<? extends Bar>,Foo<?>> loses
> the constraint between key and value type, but we expect
> @SuppressWarnings to silence it. Note that javac6 doesn't emit the warning.
>
> Is this expected behavior?
>
> Thanks,
> Raluca


More information about the compiler-dev mailing list