Mon, 17 Oct 2011 12:54:33 +0100
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
Summary: Duplicate aliasing check during subtyping leads to spurious varargs diagnostic
Reviewed-by: jjg
jjg@897 | 1 | /* |
jjg@897 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@897 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@897 | 4 | * |
jjg@897 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@897 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@897 | 7 | * published by the Free Software Foundation. |
jjg@897 | 8 | * |
jjg@897 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@897 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@897 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@897 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@897 | 13 | * accompanied this code). |
jjg@897 | 14 | * |
jjg@897 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@897 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@897 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@897 | 18 | * |
jjg@897 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@897 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@897 | 21 | * questions. |
jjg@897 | 22 | */ |
jjg@897 | 23 | |
jjg@897 | 24 | |
jjg@897 | 25 | /* |
jjg@897 | 26 | * @test |
jjg@897 | 27 | * @bug 7022337 |
jjg@897 | 28 | * @summary repeated warnings about bootclasspath not set |
jjg@897 | 29 | * @library ../lib |
jjg@897 | 30 | * @build JavacTestingAbstractProcessor T7022337 |
jjg@897 | 31 | * @run main T7022337 |
jjg@897 | 32 | */ |
jjg@897 | 33 | |
jjg@897 | 34 | import java.io.*; |
jjg@897 | 35 | import java.util.*; |
jjg@897 | 36 | import javax.annotation.processing.*; |
jjg@897 | 37 | import javax.lang.model.element.*; |
jjg@897 | 38 | import javax.tools.*; |
jjg@897 | 39 | |
jjg@897 | 40 | public class T7022337 extends JavacTestingAbstractProcessor { |
jjg@897 | 41 | public static void main(String... args) throws Exception { |
jjg@897 | 42 | new T7022337().run(); |
jjg@897 | 43 | } |
jjg@897 | 44 | |
jjg@897 | 45 | void run() throws Exception { |
jjg@897 | 46 | String myName = T7022337.class.getSimpleName(); |
jjg@897 | 47 | File testSrc = new File(System.getProperty("test.src")); |
jjg@897 | 48 | File file = new File(testSrc, myName + ".java"); |
jjg@897 | 49 | |
jjg@897 | 50 | String out = compile( |
jjg@897 | 51 | "-XDrawDiagnostics", |
jjg@897 | 52 | "-d", ".", |
jjg@897 | 53 | "-processor", myName, |
jjg@897 | 54 | "-source", "6", // explicit use of older source value without bootclasspath |
jjg@897 | 55 | file.getPath()); |
jjg@897 | 56 | |
jjg@897 | 57 | int count = 0; |
jjg@897 | 58 | for (String line: out.split("[\r\n]+")) { |
jjg@897 | 59 | if (line.contains("compiler.warn.source.no.bootclasspath")) |
jjg@897 | 60 | count++; |
jjg@897 | 61 | } |
jjg@897 | 62 | if (count != 1) |
jjg@897 | 63 | throw new Exception("unexpected number of warnings found: " + count + ", expected: 1"); |
jjg@897 | 64 | } |
jjg@897 | 65 | |
jjg@897 | 66 | String compile(String... args) throws Exception { |
jjg@897 | 67 | StringWriter sw = new StringWriter(); |
jjg@897 | 68 | PrintWriter pw = new PrintWriter(sw); |
jjg@897 | 69 | int rc = com.sun.tools.javac.Main.compile(args, pw); |
jjg@897 | 70 | pw.close(); |
jjg@897 | 71 | String out = sw.toString(); |
jjg@897 | 72 | if (!out.isEmpty()) |
jjg@897 | 73 | System.err.println(out); |
jjg@897 | 74 | if (rc != 0) |
jjg@897 | 75 | throw new Exception("compilation failed unexpectedly: rc=" + rc); |
jjg@897 | 76 | return out; |
jjg@897 | 77 | } |
jjg@897 | 78 | |
jjg@897 | 79 | // ---------- |
jjg@897 | 80 | |
jjg@897 | 81 | int round = 0; |
jjg@897 | 82 | |
jjg@897 | 83 | @Override |
jjg@897 | 84 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
jjg@897 | 85 | round++; |
jjg@897 | 86 | |
jjg@897 | 87 | final int MAXROUNDS = 3; |
jjg@897 | 88 | if (round < MAXROUNDS) |
jjg@897 | 89 | generate("Gen" + round); |
jjg@897 | 90 | |
jjg@897 | 91 | return true; |
jjg@897 | 92 | } |
jjg@897 | 93 | |
jjg@897 | 94 | void generate(String name) { |
jjg@897 | 95 | try { |
jjg@897 | 96 | JavaFileObject fo = filer.createSourceFile(name); |
jjg@897 | 97 | Writer out = fo.openWriter(); |
jjg@897 | 98 | try { |
jjg@897 | 99 | out.write("class " + name + " { }"); |
jjg@897 | 100 | } finally { |
jjg@897 | 101 | out.close(); |
jjg@897 | 102 | } |
jjg@897 | 103 | } catch (IOException e) { |
jjg@897 | 104 | throw new Error(e); |
jjg@897 | 105 | } |
jjg@897 | 106 | } |
jjg@897 | 107 | } |