T6733837.java revision 1451
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark/*
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark *
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * This code is free software; you can redistribute it and/or modify it
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * under the terms of the GNU General Public License version 2 only, as
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * published by the Free Software Foundation.
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark *
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * This code is distributed in the hope that it will be useful, but WITHOUT
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * version 2 for more details (a copy is included in the LICENSE file that
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * accompanied this code).
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark *
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * You should have received a copy of the GNU General Public License version
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * 2 along with this work; if not, write to the Free Software Foundation,
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark *
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * or visit www.oracle.com if you need additional information or have any
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * questions.
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark */
ad4485f8ff9197cf02f2a1120e665e5611455632mark
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark/*
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * @test
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * @bug 6733837
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * @summary Compiler API ignores locale settings
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * @author Maurizio Cimadamore
ad4485f8ff9197cf02f2a1120e665e5611455632mark * @library ../lib
ad4485f8ff9197cf02f2a1120e665e5611455632mark * @build ToolTester
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark * @run main T6733837
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark */
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport java.io.StringWriter;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport java.io.PrintWriter;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport java.net.URI;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport java.util.Arrays;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport java.util.List;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport javax.tools.JavaFileObject;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport javax.tools.SimpleJavaFileObject;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport static javax.tools.JavaFileObject.Kind;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkimport com.sun.source.util.JavacTask;
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmarkpublic class T6733837 extends ToolTester {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark public static void main(String... args) {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark new T6733837().exec();
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark }
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark public void exec() {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark public CharSequence getCharContent(boolean ignoreEncodingErrors) {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark return "\tclass ErroneousWithTab";
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark }
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark };
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark StringWriter sw = new StringWriter();
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark PrintWriter out = new PrintWriter(sw);
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark List<? extends JavaFileObject> files = Arrays.asList(sfo);
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark task = tool.getTask(sw, fm, null, null, null, files);
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark try {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark ((JavacTask)task).analyze();
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark }
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark catch (Throwable t) {
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark throw new Error("Compiler threw an exception");
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark }
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark System.err.println(sw.toString());
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark if (!sw.toString().contains("/Test.java"))
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark throw new Error("Bad source name in diagnostic");
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark }
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark}
51607ea01068c9047391e4c8b46bc9dbd0edb7fdmark