1 /*
2  * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 6595666
27  * @summary fix -Werror
28  * @modules jdk.compiler
29  */
30 
31 import java.io.*;
32 import java.util.*;
33 
34 public class T6595666 {
m()35     void m() {
36         // the following line must create warnings with -Xlint, because of unchecked conversion
37         List<Integer> list = new ArrayList();
38     }
39 
main(String... args)40     public static void main(String... args) throws Exception {
41         File testSrc = new File(System.getProperty("test.src", "."));
42 
43         String basename = T6595666.class.getName();
44         File srcFile = new File(testSrc, basename+".java");
45         File classFile = new File(basename+".class");
46         classFile.delete();
47         if (classFile.exists())
48             throw new Exception("setup error, can't delete " + classFile);
49 
50         compile(1, "-d", ".", "-Xlint", "-Werror", srcFile.getPath());
51         if (classFile.exists())
52             throw new Exception("failed: found " + classFile);
53 
54         compile(0, "-d", ".", "-Xlint", srcFile.getPath());
55         if (!classFile.exists())
56             throw new Exception("failed: " + classFile + " not found");
57     }
58 
compile(int rc, String... args)59     private static void compile(int rc, String... args) throws Exception {
60         System.err.println("compile: " + Arrays.asList(args));
61         StringWriter sw = new StringWriter();
62         PrintWriter pw = new PrintWriter(sw);
63         int rc2 = com.sun.tools.javac.Main.compile(args, pw);
64         pw.close();
65         System.err.println(sw);
66         if (rc != rc2)
67             throw new Exception("bad exit code; expected " + rc + ", found " + rc2);
68     }
69 }
70