395N/A/*
2362N/A * Copyright (c) 20011, Oracle and/or its affiliates. All rights reserved.
395N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
395N/A *
395N/A * This code is free software; you can redistribute it and/or modify it
395N/A * under the terms of the GNU General Public License version 2 only, as
395N/A * published by the Free Software Foundation.
395N/A *
395N/A * This code is distributed in the hope that it will be useful, but WITHOUT
395N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
395N/A * version 2 for more details (a copy is included in the LICENSE file that
395N/A * accompanied this code).
395N/A *
395N/A * You should have received a copy of the GNU General Public License version
395N/A * 2 along with this work; if not, write to the Free Software Foundation,
395N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
395N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
395N/A */
395N/A
395N/A/*
395N/A * @test
395N/A * @bug 7086261
395N/A * @summary javac doesn't report error as expected, it only reports ClientCodeWrapper$DiagnosticSourceUnwrapper
395N/A */
395N/A
395N/Aimport javax.tools.*;
395N/A
395N/Aimport com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper;
395N/Aimport com.sun.tools.javac.util.JCDiagnostic;
395N/A
395N/Aimport java.net.URI;
395N/Aimport java.util.Arrays;
395N/A
395N/Aimport static javax.tools.StandardLocation.*;
395N/Aimport static javax.tools.JavaFileObject.Kind.*;
395N/A
395N/A
395N/Apublic class T7086261 {
395N/A
395N/A static class ErroneousSource extends SimpleJavaFileObject {
395N/A public ErroneousSource() {
395N/A super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
395N/A }
395N/A public CharSequence getCharContent(boolean ignoreEncodingErrors) {
395N/A return "class Test { NonexistentClass c = null; }";
395N/A }
395N/A }
395N/A
395N/A static class DiagnosticChecker implements DiagnosticListener<javax.tools.JavaFileObject> {
395N/A public void report(Diagnostic message) {
395N/A if (!(message instanceof DiagnosticSourceUnwrapper)) {
395N/A throw new AssertionError("Wrapped diagnostic expected!");
395N/A }
395N/A String actual = message.toString();
395N/A JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d;
String expected = jd.toString();
if (!actual.equals(expected)) {
throw new AssertionError("expected = " + expected + "\nfound = " + actual);
}
}
};
void test() throws Throwable {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
JavaFileManager jfm = javac.getStandardFileManager(null, null, null);
JavaCompiler.CompilationTask task =
javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
task.call();
}
public static void main(String[] args) throws Throwable {
new T7086261().test();
}
}