8009227: Certain diagnostics should not be deferred

Tue, 05 Mar 2013 14:12:07 +0000

author
mcimadamore
date
Tue, 05 Mar 2013 14:12:07 +0000
changeset 1613
d2a98dde7ecc
parent 1612
69cd2bfd4a31
child 1614
a708c5f1da06

8009227: Certain diagnostics should not be deferred
Summary: Add new diagnostic flag to mark non deferrable diagnostics
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/abort/CompletionFailure.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Mar 05 14:04:57 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Mar 05 14:12:07 2013 +0000
     1.3 @@ -285,7 +285,7 @@
     1.4       *  @param ex         The failure to report.
     1.5       */
     1.6      public Type completionError(DiagnosticPosition pos, CompletionFailure ex) {
     1.7 -        log.error(pos, "cant.access", ex.sym, ex.getDetailValue());
     1.8 +        log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, pos, "cant.access", ex.sym, ex.getDetailValue());
     1.9          if (ex instanceof ClassReader.BadClassFile
    1.10                  && !suppressAbortOnBadClassFile) throw new Abort();
    1.11          else return syms.errType;
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Tue Mar 05 14:04:57 2013 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Tue Mar 05 14:12:07 2013 +0000
     2.3 @@ -303,11 +303,6 @@
     2.4              attr.attribTree(newTree, speculativeEnv, resultInfo);
     2.5              unenterScanner.scan(newTree);
     2.6              return newTree;
     2.7 -        } catch (Abort ex) {
     2.8 -            //if some very bad condition occurred during deferred attribution
     2.9 -            //we should dump all errors before killing javac
    2.10 -            deferredDiagnosticHandler.reportDeferredDiagnostics();
    2.11 -            throw ex;
    2.12          } finally {
    2.13              unenterScanner.scan(newTree);
    2.14              log.popDiagnosticHandler(deferredDiagnosticHandler);
     3.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Tue Mar 05 14:04:57 2013 +0000
     3.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Tue Mar 05 14:12:07 2013 +0000
     3.3 @@ -347,7 +347,8 @@
     3.4          MANDATORY,
     3.5          RESOLVE_ERROR,
     3.6          SYNTAX,
     3.7 -        RECOVERABLE
     3.8 +        RECOVERABLE,
     3.9 +        NON_DEFERRABLE,
    3.10      }
    3.11  
    3.12      private final DiagnosticType type;
     4.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Mar 05 14:04:57 2013 +0000
     4.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Mar 05 14:12:07 2013 +0000
     4.3 @@ -136,10 +136,12 @@
     4.4          }
     4.5  
     4.6          public void report(JCDiagnostic diag) {
     4.7 -            if (filter == null || filter.accepts(diag))
     4.8 +            if (!diag.isFlagSet(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE) &&
     4.9 +                (filter == null || filter.accepts(diag))) {
    4.10                  deferred.add(diag);
    4.11 -            else
    4.12 +            } else {
    4.13                  prev.report(diag);
    4.14 +            }
    4.15          }
    4.16  
    4.17          public Queue<JCDiagnostic> getDiagnostics() {
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/lambda/abort/CompletionFailure.java	Tue Mar 05 14:12:07 2013 +0000
     5.3 @@ -0,0 +1,137 @@
     5.4 +/*
     5.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 8009227
    5.30 + * @summary Certain diagnostics should not be deferred
    5.31 + */
    5.32 +
    5.33 +import com.sun.source.util.JavacTask;
    5.34 +import java.io.BufferedWriter;
    5.35 +import java.io.File;
    5.36 +import java.io.FileWriter;
    5.37 +import java.io.IOException;
    5.38 +import java.util.Arrays;
    5.39 +import javax.tools.Diagnostic;
    5.40 +import javax.tools.JavaCompiler;
    5.41 +import javax.tools.JavaFileObject;
    5.42 +import javax.tools.SimpleJavaFileObject;
    5.43 +import javax.tools.ToolProvider;
    5.44 +
    5.45 +public class CompletionFailure {
    5.46 +
    5.47 +    public static void main(String... args) throws Exception {
    5.48 +
    5.49 +        String SCRATCH_DIR = System.getProperty("user.dir");
    5.50 +        JavaCompiler javacTool = ToolProvider.getSystemJavaCompiler();
    5.51 +        File scratchDir = new File(SCRATCH_DIR);
    5.52 +
    5.53 +        sourceA.dumpTo(scratchDir);
    5.54 +        sourceB.dumpTo(scratchDir);
    5.55 +
    5.56 +        JavacTask ct = (JavacTask)javacTool.getTask(null, null, null,
    5.57 +                null, null, Arrays.asList(sourceA.asJFO(scratchDir), sourceB.asJFO(scratchDir)));
    5.58 +
    5.59 +        ct.generate();
    5.60 +
    5.61 +        remove(scratchDir, "A.java");
    5.62 +        remove(scratchDir, "B.java");
    5.63 +        remove(scratchDir, "A.class");
    5.64 +
    5.65 +        sourceC.dumpTo(scratchDir);
    5.66 +        sourceD.dumpTo(scratchDir);
    5.67 +
    5.68 +        DiagnosticChecker diagChecker = new DiagnosticChecker();
    5.69 +        ct = (JavacTask)javacTool.getTask(null, null, diagChecker,
    5.70 +                Arrays.asList("-XDrawDiagnostics", "-cp", scratchDir.getAbsolutePath()),
    5.71 +                null, Arrays.asList(sourceC.asJFO(scratchDir), sourceD.asJFO(scratchDir)));
    5.72 +        try {
    5.73 +            ct.analyze();
    5.74 +        } catch (Throwable ex) {
    5.75 +            //ignore abort exception thrown by javac
    5.76 +        }
    5.77 +
    5.78 +        if (!diagChecker.errorFound) {
    5.79 +            throw new AssertionError("Missing diagnostic");
    5.80 +        }
    5.81 +    }
    5.82 +
    5.83 +    static void remove(File dir, String fileName) {
    5.84 +        File fileToRemove = new File(dir, fileName);
    5.85 +        fileToRemove.delete();
    5.86 +    }
    5.87 +
    5.88 +    static class JavaSource {
    5.89 +        String contents;
    5.90 +        String filename;
    5.91 +
    5.92 +        public JavaSource(String filename, String contents) {
    5.93 +            this.filename =  filename;
    5.94 +            this.contents = contents;
    5.95 +        }
    5.96 +
    5.97 +        void dumpTo(java.io.File loc) throws Exception {
    5.98 +            File file = new File(loc, filename);
    5.99 +            BufferedWriter bw = new java.io.BufferedWriter(new FileWriter(file));
   5.100 +            bw.append(contents);
   5.101 +            bw.close();
   5.102 +        }
   5.103 +
   5.104 +        SimpleJavaFileObject asJFO(java.io.File dir) {
   5.105 +            return new SimpleJavaFileObject(new File(dir, filename).toURI(), JavaFileObject.Kind.SOURCE) {
   5.106 +                @Override
   5.107 +                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   5.108 +                    return contents;
   5.109 +                }
   5.110 +            };
   5.111 +        }
   5.112 +    }
   5.113 +
   5.114 +    static JavaSource sourceA = new JavaSource("A.java", "public interface A { }\n");
   5.115 +
   5.116 +    static JavaSource sourceB = new JavaSource("B.java", "public class B implements A {\n" +
   5.117 +                                               "   public static Object n() { return null; }\n" +
   5.118 +                                               "}\n");
   5.119 +
   5.120 +    static JavaSource sourceC = new JavaSource("C.java", "public class C {\n" +
   5.121 +                                               "   void test(B b) {\n" +
   5.122 +                                               "      D.m(B.n());\n" +
   5.123 +                                               "}  }\n");
   5.124 +
   5.125 +    static JavaSource sourceD = new JavaSource("D.java", "public class D {\n" +
   5.126 +                                               "   static void m(Object o) { }\n" +
   5.127 +                                               "}\n");
   5.128 +
   5.129 +    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
   5.130 +
   5.131 +        boolean errorFound;
   5.132 +
   5.133 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
   5.134 +            if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
   5.135 +                    diagnostic.getCode().contains("compiler.err.cant.access")) {
   5.136 +                errorFound = true;
   5.137 +            }
   5.138 +        }
   5.139 +    }
   5.140 +}

mercurial