Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6410653/T6410653.java
38813 views
/*1* Copyright (c) 2006, 2011, 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 6410653 640127726* @summary REGRESSION: javac crashes if -d or -s argument is a file27* @author Peter von der Ah\u00e928*/2930import java.lang.reflect.Field;31import java.io.File;32import java.io.ByteArrayOutputStream;33import javax.tools.*;3435public class T6410653 {36public static void main(String... args) throws Exception {37File testSrc = new File(System.getProperty("test.src"));38String source = new File(testSrc, "T6410653.java").getPath();39ClassLoader cl = ToolProvider.getSystemToolClassLoader();40Tool compiler = ToolProvider.getSystemJavaCompiler();41Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);42Field useRawMessages = log.getDeclaredField("useRawMessages");43useRawMessages.setAccessible(true);44useRawMessages.setBoolean(null, true);45ByteArrayOutputStream out = new ByteArrayOutputStream();46compiler.run(null, null, out, "-d", source, source);47useRawMessages.setBoolean(null, false);48if (!out.toString().equals(String.format("%s%n%s%n",49"javac: javac.err.file.not.directory",50"javac.msg.usage"))) {51throw new AssertionError(out);52}53System.out.println("Test PASSED. Running javac again to see localized output:");54compiler.run(null, null, System.out, "-d", source, source);55}56}575859