Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6400383/T6400383.java
38813 views
/*1* Copyright (c) 2006, 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*/2829import java.io.*;30import com.sun.tools.javac.api.*;3132public class T6400383 {33public static void main(String... args) {34File foo = new File("foo.java");35foo.delete();3637// case 1: file not found38JavacTool tool = JavacTool.create();39StringStream out = new StringStream();40tool.run(null, out, out, foo.getPath());41check(out.toString());424344// case 2: file is a directory45out.clear();46try {47foo.mkdir();48tool.run(null, out, out, foo.getPath());49check(out.toString());50} finally {51foo.delete();52}53}5455private static void check(String s) {56System.err.println(s);57// If the compiler crashed and caught the error, it will print out58// the "oh golly, I crashed!" message, which will contain the Java59// name of the exception in the stack trace ... so look for the60// string "Exception" or "Error".61if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1)62throw new AssertionError("found exception");63}6465private static class StringStream extends OutputStream {66public void write(int i) {67sb.append((char) i);68}6970void clear() {71sb.setLength(0);72}7374public String toString() {75return sb.toString();76}7778private StringBuilder sb = new StringBuilder();79}80}818283