test/tools/javac/api/7086261/T7086261.java

Wed, 23 Jan 2013 20:57:40 +0000

author
vromero
date
Wed, 23 Jan 2013 20:57:40 +0000
changeset 1520
5c956be64b9e
parent 1305
9d47f4850714
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8006694: temporarily workaround combo tests are causing time out in several platforms
Reviewed-by: jjg
Contributed-by: maurizio.cimadamore@oracle.com

     1 /*
     2  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 7086261
    27  * @summary javac doesn't report error as expected, it only reports ClientCodeWrapper$DiagnosticSourceUnwrapper
    28  */
    30 import javax.tools.*;
    32 import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper;
    33 import com.sun.tools.javac.util.JCDiagnostic;
    35 import java.net.URI;
    36 import java.util.Arrays;
    38 import static javax.tools.StandardLocation.*;
    39 import static javax.tools.JavaFileObject.Kind.*;
    42 public class T7086261 {
    44     static class ErroneousSource extends SimpleJavaFileObject {
    45         public ErroneousSource() {
    46             super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    47         }
    48         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
    49             return "class Test { NonexistentClass c = null; }";
    50         }
    51     }
    53     static class DiagnosticChecker implements DiagnosticListener<javax.tools.JavaFileObject> {
    54         public void report(Diagnostic message) {
    55             if (!(message instanceof DiagnosticSourceUnwrapper)) {
    56                 throw new AssertionError("Wrapped diagnostic expected!");
    57             }
    58             String actual = message.toString();
    59             JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d;
    60             String expected = jd.toString();
    61             if (!actual.equals(expected)) {
    62                 throw new AssertionError("expected = " + expected + "\nfound = " + actual);
    63             }
    64         }
    65     };
    67     void test() throws Throwable {
    68         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
    69         JavaFileManager jfm = javac.getStandardFileManager(null, null, null);
    70         JavaCompiler.CompilationTask task =
    71                 javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
    72         task.call();
    73     }
    75     public static void main(String[] args) throws Throwable {
    76         new T7086261().test();
    77     }
    78 }

mercurial