Mon, 28 Feb 2011 13:42:24 -0800
7022711: compiler crash in try-with-resources
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2006, 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 */
24 /**
25 * @test
26 * @bug 6397104
27 * @summary JSR 199: JavaFileManager.getFileForOutput should have sibling argument
28 * @author Peter von der Ah\u00e9
29 * @ignore this test should be rewritten when fixing 6473901
30 */
32 import java.io.File;
33 import java.util.Arrays;
34 import javax.tools.*;
35 import javax.tools.JavaFileManager.Location;
37 import static javax.tools.StandardLocation.CLASS_OUTPUT;
39 public class T6397104 {
41 JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
43 void test(StandardJavaFileManager fm,
44 Location location,
45 File siblingFile,
46 String relName,
47 String expectedPath)
48 throws Exception
49 {
50 JavaFileObject sibling = siblingFile == null
51 ? null
52 : fm.getJavaFileObjectsFromFiles(Arrays.asList(siblingFile)).iterator().next();
53 FileObject fileObject =
54 fm.getFileForOutput(location, "java.lang", relName, sibling);
55 if (!fileObject.toUri().getPath().equals(expectedPath))
56 throw new AssertionError("Expected " + expectedPath +
57 ", got " + fileObject.toUri().getPath());
58 System.out.format("OK: (%s, %s) => %s%n", siblingFile, relName, fileObject.toUri());
59 }
61 void test(boolean hasLocation, File siblingFile, String relName, String expectedPath)
62 throws Exception
63 {
64 StandardJavaFileManager fm;
65 if (hasLocation) {
66 for (Location location : StandardLocation.values()) {
67 fm = tool.getStandardFileManager(null, null, null);
68 fm.setLocation(location, Arrays.asList(new File(".")));
69 test(fm, location, siblingFile, relName, expectedPath);
70 }
71 } else {
72 fm = tool.getStandardFileManager(null, null, null);
73 test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
74 }
75 }
77 public static void main(String... args) throws Exception {
78 T6397104 tester = new T6397104();
79 tester.test(false,
80 new File(new File("foo", "bar"), "baz.java"),
81 "qux/baz.xml",
82 "foo/bar/baz.xml");
83 tester.test(false,
84 null,
85 "qux/baz.xml",
86 "baz.xml"); // sb "java/lang/qux/baz.xml"
87 tester.test(true,
88 new File(new File("foo", "bar"), "baz.java"),
89 "qux/baz.xml",
90 "./java/lang/qux/baz.xml");
91 tester.test(true,
92 null,
93 "qux/baz.xml",
94 "./java/lang/qux/baz.xml");
95 }
97 }