United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7097436 Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
JDK-7097436 : Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs

Details
Type:
Bug
Submit Date:
2011-10-03
Status:
Closed
Updated Date:
2012-02-24
Project Name:
JDK
Resolved Date:
2012-02-24
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
unknown
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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
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.
                                     
2011-10-03
SUGGESTED FIX

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



Hardware and Software, Engineered to Work Together