1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/6400383/T6400383.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,81 @@ 1.4 +/* 1.5 + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6400383 1.30 + * @summary directory foo.java on javac command line causes javac to crash 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import com.sun.tools.javac.api.*; 1.35 + 1.36 +public class T6400383 { 1.37 + public static void main(String... args) { 1.38 + File foo = new File("foo.java"); 1.39 + foo.delete(); 1.40 + 1.41 + // case 1: file not found 1.42 + JavacTool tool = JavacTool.create(); 1.43 + StringStream out = new StringStream(); 1.44 + tool.run(null, out, out, foo.getPath()); 1.45 + check(out.toString()); 1.46 + 1.47 + 1.48 + // case 2: file is a directory 1.49 + out.clear(); 1.50 + try { 1.51 + foo.mkdir(); 1.52 + tool.run(null, out, out, foo.getPath()); 1.53 + check(out.toString()); 1.54 + } finally { 1.55 + foo.delete(); 1.56 + } 1.57 + } 1.58 + 1.59 + private static void check(String s) { 1.60 + System.err.println(s); 1.61 + // If the compiler crashed and caught the error, it will print out 1.62 + // the "oh golly, I crashed!" message, which will contain the Java 1.63 + // name of the exception in the stack trace ... so look for the 1.64 + // string "Exception" or "Error". 1.65 + if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1) 1.66 + throw new AssertionError("found exception"); 1.67 + } 1.68 + 1.69 + private static class StringStream extends OutputStream { 1.70 + public void write(int i) { 1.71 + sb.append((char) i); 1.72 + } 1.73 + 1.74 + void clear() { 1.75 + sb.setLength(0); 1.76 + } 1.77 + 1.78 + public String toString() { 1.79 + return sb.toString(); 1.80 + } 1.81 + 1.82 + private StringBuilder sb = new StringBuilder(); 1.83 + } 1.84 +}