1 | /*
|
---|
2 | * Copyright (c) 2008, 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 6759996
|
---|
27 | * @summary javac should ignore empty entries on paths
|
---|
28 | */
|
---|
29 |
|
---|
30 | import java.io.File;
|
---|
31 | import java.io.FileWriter;
|
---|
32 | import java.io.IOException;
|
---|
33 | import java.io.PrintWriter;
|
---|
34 | import java.io.StringWriter;
|
---|
35 | import java.io.Writer;
|
---|
36 |
|
---|
37 | public class T6759996 {
|
---|
38 | public static void main(String[] args) throws Exception {
|
---|
39 | new T6759996().run();
|
---|
40 | }
|
---|
41 |
|
---|
42 | void run() throws IOException, InterruptedException {
|
---|
43 | String PS = File.pathSeparator;
|
---|
44 | write(new File("A.java"), "class A { }");
|
---|
45 | write(new File("B.java"), "class B extends A { }");
|
---|
46 | // In the following line, the presence of the empty element
|
---|
47 | // should not mask the presence of the "." element on the path
|
---|
48 | javac("-verbose", "-sourcepath", "" + PS + ".", "B.java");
|
---|
49 | }
|
---|
50 |
|
---|
51 | void javac(String... args) throws IOException, InterruptedException {
|
---|
52 | StringWriter sw = new StringWriter();
|
---|
53 | PrintWriter out = new PrintWriter(sw);
|
---|
54 | int rc = com.sun.tools.javac.Main.compile(args, out);
|
---|
55 | System.out.println(sw.toString());
|
---|
56 | if (rc != 0)
|
---|
57 | throw new Error("javac failed: rc=" + rc);
|
---|
58 |
|
---|
59 | }
|
---|
60 |
|
---|
61 | void write(File to, String body) throws IOException {
|
---|
62 | System.err.println("write " + to);
|
---|
63 | File toDir = to.getParentFile();
|
---|
64 | if (toDir != null) {
|
---|
65 | boolean ok = toDir.mkdirs();
|
---|
66 | if (!ok) {
|
---|
67 | throw new Error("could not create directory " + toDir);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | Writer out = new FileWriter(to);
|
---|
71 | try {
|
---|
72 | out.write(body);
|
---|
73 | if (!body.endsWith("\n"))
|
---|
74 | out.write("\n");
|
---|
75 | } finally {
|
---|
76 | out.close();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|