JDK-7097436 : Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: unknown
  • Submitted: 2011-10-03
  • Updated: 2012-02-24
  • Resolved: 2012-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b12Fixed
Description
This program:

import java.util.ArrayList;
import java.util.List;

 class X {
        @SafeVarargs
        static void m(List<String>... ls) {
                Object[] o = ls; // 2 warning here
                o[0] = new ArrayList<Integer>();
                System.out.println(o);
        }
} 


Generates two 'varargs' warnings when compiled with the -Xlint:varargs flag enabled.

OUTPUT:

Test.java:7: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter ls
                Object[] o = ls; // 2 warning here
                             ^
Test.java:7: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter ls
                Object[] o = ls; // 2 warning here
                             ^
2 warnings

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk8/tl/langtools/rev/b5d0b8effc85
17-10-2011

EVALUATION The problem is caused by the fact that the check for unsound varargs use is performed twice, once in the convertibility check and once in the unchecked subtype routine check. Since the former uses the latter, in some cases it is possible to end up with duplicate diagnostics.
03-10-2011