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