Path: blob/master/test/langtools/tools/javac/6400383/T6400383.java
41149 views
/*1* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 640038326* @summary directory foo.java on javac command line causes javac to crash27* @modules jdk.compiler/com.sun.tools.javac.api28*/2930import java.io.*;31import com.sun.tools.javac.api.*;3233public class T6400383 {34public static void main(String... args) {35File foo = new File("foo.java");36foo.delete();3738// case 1: file not found39JavacTool tool = JavacTool.create();40StringStream out = new StringStream();41tool.run(null, out, out, foo.getPath());42check(out.toString());434445// case 2: file is a directory46out.clear();47try {48foo.mkdir();49tool.run(null, out, out, foo.getPath());50check(out.toString());51} finally {52foo.delete();53}54}5556private static void check(String s) {57System.err.println(s);58// If the compiler crashed and caught the error, it will print out59// the "oh golly, I crashed!" message, which will contain the Java60// name of the exception in the stack trace ... so look for the61// string "Exception" or "Error".62if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1)63throw new AssertionError("found exception");64}6566private static class StringStream extends OutputStream {67public void write(int i) {68sb.append((char) i);69}7071void clear() {72sb.setLength(0);73}7475public String toString() {76return sb.toString();77}7879private StringBuilder sb = new StringBuilder();80}81}828384