test/tools/javac/T6759996.java

Wed, 12 Aug 2009 10:34:13 -0700

author
jjg
date
Wed, 12 Aug 2009 10:34:13 -0700
changeset 372
7dbb79875a63
parent 151
8ae974495e73
child 554
9d9f26857129
permissions
-rw-r--r--

6558476: com/sun/tools/javac/Main.compile don't release file handles on return
Reviewed-by: darcy

     1 /*
     2  * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6759996
    27  * @summary javac should ignore empty entries on paths
    28  */
    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;
    37 public class T6759996 {
    38     public static void main(String[] args) throws Exception {
    39         new T6759996().run();
    40     }
    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     }
    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);
    59     }
    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 }

mercurial