test/tools/javac/6400383/T6400383.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2006 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 6400383
    27  * @summary directory foo.java on javac command line causes javac to crash
    28  */
    30 import java.io.*;
    31 import com.sun.tools.javac.api.*;
    33 public class T6400383 {
    34     public static void main(String... args) {
    35         File foo = new File("foo.java");
    36         foo.delete();
    38         // case 1: file not found
    39         JavacTool tool = JavacTool.create();
    40         StringStream out = new StringStream();
    41         tool.run(null, out, out, foo.getPath());
    42         check(out.toString());
    45         // case 2: file is a directory
    46         out.clear();
    47         try {
    48             foo.mkdir();
    49             tool.run(null, out, out, foo.getPath());
    50             check(out.toString());
    51         } finally {
    52             foo.delete();
    53         }
    54     }
    56     private static void check(String s) {
    57         System.err.println(s);
    58         // If the compiler crashed and caught the error, it will print out
    59         // the "oh golly, I crashed!" message, which will contain the Java
    60         // name of the exception in the stack trace ... so look for the
    61         // string "Exception" or "Error".
    62         if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1)
    63             throw new AssertionError("found exception");
    64     }
    66     private static class StringStream extends OutputStream {
    67         public void write(int i) {
    68             sb.append((char) i);
    69         }
    71         void clear() {
    72             sb.setLength(0);
    73         }
    75         public String toString() {
    76             return sb.toString();
    77         }
    79         private StringBuilder sb = new StringBuilder();
    80     }
    81 }

mercurial