T6400383.java revision 553:9d9f26857129
11771SN/A/* 21771SN/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 31771SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41771SN/A * 51771SN/A * This code is free software; you can redistribute it and/or modify it 62362SN/A * under the terms of the GNU General Public License version 2 only, as 71771SN/A * published by the Free Software Foundation. 82362SN/A * 91771SN/A * This code is distributed in the hope that it will be useful, but WITHOUT 101771SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111771SN/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121771SN/A * version 2 for more details (a copy is included in the LICENSE file that 131771SN/A * accompanied this code). 141771SN/A * 151771SN/A * You should have received a copy of the GNU General Public License version 161771SN/A * 2 along with this work; if not, write to the Free Software Foundation, 171771SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181771SN/A * 191771SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 202362SN/A * or visit www.oracle.com if you need additional information or have any 212362SN/A * questions. 222362SN/A */ 231771SN/A 241771SN/A/* 251771SN/A * @test 261771SN/A * @bug 6400383 271771SN/A * @summary directory foo.java on javac command line causes javac to crash 281771SN/A */ 291771SN/A 301771SN/Aimport java.io.*; 311771SN/Aimport com.sun.tools.javac.api.*; 321771SN/A 333984SN/Apublic class T6400383 { 341771SN/A public static void main(String... args) { 351771SN/A File foo = new File("foo.java"); 361771SN/A foo.delete(); 371771SN/A 3815088Sdl // case 1: file not found 3915088Sdl JavacTool tool = JavacTool.create(); 401771SN/A StringStream out = new StringStream(); 4112876Sdl tool.run(null, out, out, foo.getPath()); 421771SN/A check(out.toString()); 431771SN/A 441771SN/A 4516631Sdl // case 2: file is a directory 461771SN/A out.clear(); 477623SN/A try { 487623SN/A foo.mkdir(); 4912876Sdl tool.run(null, out, out, foo.getPath()); 507623SN/A check(out.toString()); 5116631Sdl } finally { 522754SN/A foo.delete(); 531771SN/A } 541771SN/A } 551771SN/A 561771SN/A private static void check(String s) { 571771SN/A System.err.println(s); 581771SN/A // If the compiler crashed and caught the error, it will print out 591771SN/A // the "oh golly, I crashed!" message, which will contain the Java 601771SN/A // name of the exception in the stack trace ... so look for the 614118SN/A // string "Exception" or "Error". 624118SN/A if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1) 631771SN/A throw new AssertionError("found exception"); 644118SN/A } 654118SN/A 661771SN/A private static class StringStream extends OutputStream { 6716631Sdl public void write(int i) { 6816631Sdl sb.append((char) i); 6916631Sdl } 7016631Sdl 7116631Sdl void clear() { 7216631Sdl sb.setLength(0); 7316631Sdl } 7416631Sdl 751771SN/A public String toString() { 761771SN/A return sb.toString(); 771771SN/A } 781771SN/A 791771SN/A private StringBuilder sb = new StringBuilder(); 801771SN/A } 811771SN/A} 821771SN/A