test/tools/javac/T6759996.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

jjg@151 1 /*
ohair@554 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
jjg@151 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@151 4 *
jjg@151 5 * This code is free software; you can redistribute it and/or modify it
jjg@151 6 * under the terms of the GNU General Public License version 2 only, as
jjg@151 7 * published by the Free Software Foundation.
jjg@151 8 *
jjg@151 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@151 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@151 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@151 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@151 13 * accompanied this code).
jjg@151 14 *
jjg@151 15 * You should have received a copy of the GNU General Public License version
jjg@151 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@151 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@151 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jjg@151 22 */
jjg@151 23
jjg@151 24 /*
jjg@151 25 * @test
jjg@151 26 * @bug 6759996
jjg@151 27 * @summary javac should ignore empty entries on paths
jjg@151 28 */
jjg@151 29
jjg@151 30 import java.io.File;
jjg@151 31 import java.io.FileWriter;
jjg@151 32 import java.io.IOException;
jjg@151 33 import java.io.PrintWriter;
jjg@151 34 import java.io.StringWriter;
jjg@151 35 import java.io.Writer;
jjg@151 36
jjg@151 37 public class T6759996 {
jjg@151 38 public static void main(String[] args) throws Exception {
jjg@151 39 new T6759996().run();
jjg@151 40 }
jjg@151 41
jjg@151 42 void run() throws IOException, InterruptedException {
jjg@151 43 String PS = File.pathSeparator;
jjg@151 44 write(new File("A.java"), "class A { }");
jjg@151 45 write(new File("B.java"), "class B extends A { }");
jjg@151 46 // In the following line, the presence of the empty element
jjg@151 47 // should not mask the presence of the "." element on the path
jjg@151 48 javac("-verbose", "-sourcepath", "" + PS + ".", "B.java");
jjg@151 49 }
jjg@151 50
jjg@151 51 void javac(String... args) throws IOException, InterruptedException {
jjg@151 52 StringWriter sw = new StringWriter();
jjg@151 53 PrintWriter out = new PrintWriter(sw);
jjg@151 54 int rc = com.sun.tools.javac.Main.compile(args, out);
jjg@151 55 System.out.println(sw.toString());
jjg@151 56 if (rc != 0)
jjg@151 57 throw new Error("javac failed: rc=" + rc);
jjg@151 58
jjg@151 59 }
jjg@151 60
jjg@151 61 void write(File to, String body) throws IOException {
jjg@151 62 System.err.println("write " + to);
jjg@151 63 File toDir = to.getParentFile();
jjg@151 64 if (toDir != null) {
jjg@151 65 boolean ok = toDir.mkdirs();
jjg@151 66 if (!ok) {
jjg@151 67 throw new Error("could not create directory " + toDir);
jjg@151 68 }
jjg@151 69 }
jjg@151 70 Writer out = new FileWriter(to);
jjg@151 71 try {
jjg@151 72 out.write(body);
jjg@151 73 if (!body.endsWith("\n"))
jjg@151 74 out.write("\n");
jjg@151 75 } finally {
jjg@151 76 out.close();
jjg@151 77 }
jjg@151 78 }
jjg@151 79 }

mercurial