T6410653.java revision 3779:7d2f8aa366e2
159191Skris/*
255714Skris * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
355714Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
455714Skris *
555714Skris * This code is free software; you can redistribute it and/or modify it
655714Skris * under the terms of the GNU General Public License version 2 only, as
755714Skris * published by the Free Software Foundation.
855714Skris *
955714Skris * This code is distributed in the hope that it will be useful, but WITHOUT
1055714Skris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1155714Skris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1255714Skris * version 2 for more details (a copy is included in the LICENSE file that
1355714Skris * accompanied this code).
1455714Skris *
1555714Skris * You should have received a copy of the GNU General Public License version
1655714Skris * 2 along with this work; if not, write to the Free Software Foundation,
1755714Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1855714Skris *
1955714Skris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2055714Skris * or visit www.oracle.com if you need additional information or have any
2155714Skris * questions.
2255714Skris */
2355714Skris
2455714Skris/**
2555714Skris * @test
2655714Skris * @bug     6410653 6401277
2759191Skris * @summary REGRESSION: javac crashes if -d or -s argument is a file
2859191Skris * @author  Peter von der Ah\u00e9
2955714Skris * @modules java.compiler
3055714Skris *          jdk.compiler/com.sun.tools.javac.util
3159191Skris */
3259191Skris
3359191Skrisimport java.lang.reflect.Field;
3459191Skrisimport java.lang.reflect.Module;
3559191Skrisimport java.io.File;
3655714Skrisimport java.io.ByteArrayOutputStream;
3755714Skrisimport javax.tools.*;
3859191Skris
3959191Skrispublic class T6410653 {
4059191Skris    public static void main(String... args) throws Exception {
4159191Skris        File testSrc = new File(System.getProperty("test.src"));
4259191Skris        String source = new File(testSrc, "T6410653.java").getPath();
4359191Skris        Tool compiler = ToolProvider.getSystemJavaCompiler();
4459191Skris        Module compilerModule = compiler.getClass().getModule();
4559191Skris        Class<?> log = Class.forName(compilerModule, "com.sun.tools.javac.util.Log");
4655714Skris        Field useRawMessages = log.getDeclaredField("useRawMessages");
4755714Skris        useRawMessages.setAccessible(true);
4855714Skris        useRawMessages.setBoolean(null, true);
4955714Skris        ByteArrayOutputStream out = new ByteArrayOutputStream();
5055714Skris        compiler.run(null, null, out, "-d", source, source);
5155714Skris        System.err.println(">>>" + out + "<<<");
5255714Skris        useRawMessages.setBoolean(null, false);
5355714Skris        if (!out.toString().equals(String.format("%s%n",
5455714Skris                                                 "javac: javac.err.file.not.directory"))) {
5555714Skris            throw new AssertionError(out);
5655714Skris        }
5755714Skris        System.out.println("Test PASSED.  Running javac again to see localized output:");
5855714Skris        compiler.run(null, null, System.out, "-d", source, source);
5955714Skris    }
6055714Skris}
6155714Skris