changeset 43269:12f989542165

8171098: NPE when --add-modules java.corba is used Summary: Block annotations queue until enter is done, to avoid flushing annotations during module resolution. Reviewed-by: jjg
author jlahoda
date Fri, 20 Jan 2017 09:26:49 +0100
parents 12436ebea906
children de9a02e20567
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocEnter.java langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocTool.java langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java langtools/test/tools/javac/lib/combo/ReusableContext.java langtools/test/tools/javac/modules/EdgeCases.java
diffstat 9 files changed, 95 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Fri Jan 20 09:26:49 2017 +0100
@@ -118,6 +118,8 @@
         Source source = Source.instance(context);
         allowRepeatedAnnos = source.allowRepeatedAnnotations();
         sourceName = source.name;
+
+        blockCount = 1;
     }
 
     /** Semaphore to delay annotation processing */
@@ -144,6 +146,10 @@
     /** are we blocking annotation processing? */
     public boolean annotationsBlocked() {return blockCount > 0; }
 
+    public void enterDone() {
+        unblockAnnotations();
+    }
+
     public List<TypeCompound> fromAnnotations(List<JCAnnotation> annotations) {
         if (annotations.isEmpty()) {
             return List.nil();
@@ -1316,4 +1322,8 @@
                     }
                 };
     }
+
+    public void newRound() {
+        blockCount = 1;
+    }
 }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -363,7 +363,7 @@
      **/
     protected boolean implicitSourceFilesRead;
 
-    protected boolean enterDone;
+    private boolean enterDone;
 
     protected CompileStates compileStates;
 
@@ -1042,7 +1042,7 @@
     public List<JCCompilationUnit> initModules(List<JCCompilationUnit> roots) {
         modules.initModules(roots);
         if (roots.isEmpty()) {
-            enterDone = true;
+            enterDone();
         }
         return roots;
     }
@@ -1063,7 +1063,7 @@
 
         enter.main(roots);
 
-        enterDone = true;
+        enterDone();
 
         if (!taskListener.isEmpty()) {
             for (JCCompilationUnit unit: roots) {
@@ -1725,6 +1725,11 @@
         }
     }
 
+    public void enterDone() {
+        enterDone = true;
+        annotate.enterDone();
+    }
+
     public boolean isEnterDone() {
         return enterDone;
     }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -92,6 +92,7 @@
 
 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
 import static com.sun.tools.javac.code.Kinds.Kind.*;
+import com.sun.tools.javac.comp.Annotate;
 import static com.sun.tools.javac.comp.CompileStates.CompileState;
 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
 
@@ -123,6 +124,7 @@
     private final JavaCompiler compiler;
     private final Modules modules;
     private final Types types;
+    private final Annotate annotate;
 
     /**
      * Holds relevant state history of which processors have been
@@ -219,6 +221,7 @@
         typeUtils = JavacTypes.instance(context);
         modules = Modules.instance(context);
         types = Types.instance(context);
+        annotate = Annotate.instance(context);
         processorOptions = initProcessorOptions();
         unmatchedProcessorOptions = initUnmatchedProcessorOptions();
         messages = JavacMessages.instance(context);
@@ -1256,6 +1259,7 @@
             compiler.newRound();
             modules.newRound();
             types.newRound();
+            annotate.newRound();
 
             boolean foundError = false;
 
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocEnter.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocEnter.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
 import com.sun.tools.javac.util.List;
 
 import static com.sun.tools.javac.code.Kinds.Kind.*;
+import com.sun.tools.javac.main.JavaCompiler;
 
 /**
  *  Javadoc's own enter phase does a few things above and beyond that
@@ -65,16 +66,19 @@
         super(context);
         messager = Messager.instance0(context);
         docenv = DocEnv.instance(context);
+        compiler = JavaCompiler.instance(context);
     }
 
     final Messager messager;
     final DocEnv docenv;
+    final JavaCompiler compiler;
 
     @Override
     public void main(List<JCCompilationUnit> trees) {
         // count all Enter errors as warnings.
         int nerrors = messager.nerrors;
         super.main(trees);
+        compiler.enterDone();
         messager.nwarnings += (messager.nerrors - nerrors);
         messager.nerrors = nerrors;
     }
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocTool.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocTool.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -219,7 +219,6 @@
             // Enter symbols for all files
             docenv.notice("main.Building_tree");
             javadocEnter.main(classTrees.toList().appendList(packageTrees.toList()));
-            enterDone = true;
         } catch (Abort ex) {}
 
         if (messager.nerrors() != 0)
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
 import com.sun.tools.javac.util.List;
 
 import static com.sun.tools.javac.code.Kinds.Kind.*;
+import com.sun.tools.javac.main.JavaCompiler;
 
 /**
  *  Javadoc's own enter phase does a few things above and beyond that
@@ -64,16 +65,19 @@
         super(context);
         messager = Messager.instance0(context);
         toolEnv = ToolEnvironment.instance(context);
+        compiler = JavaCompiler.instance(context);
     }
 
     final Messager messager;
     final ToolEnvironment toolEnv;
+    final JavaCompiler compiler;
 
     @Override
     public void main(List<JCCompilationUnit> trees) {
         // count all Enter errors as warnings.
         int nerrors = messager.nerrors;
         super.main(trees);
+        compiler.enterDone();
         messager.nwarnings += (messager.nerrors - nerrors);
         messager.nerrors = nerrors;
     }
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -202,7 +202,6 @@
             javadocEnter.main(classTrees.toList().appendList(packageTrees));
             etable.setClassDeclList(listClasses(classTrees.toList()));
 
-            enterDone = true;
             etable.analyze();
         } catch (CompletionFailure cf) {
             throw new ToolException(ABNORMAL, cf.getMessage(), cf);
--- a/langtools/test/tools/javac/lib/combo/ReusableContext.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/test/tools/javac/lib/combo/ReusableContext.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
 import com.sun.tools.javac.code.Type.ClassType;
 import com.sun.tools.javac.code.TypeTag;
 import com.sun.tools.javac.code.Types;
+import com.sun.tools.javac.comp.Annotate;
 import com.sun.tools.javac.comp.Check;
 import com.sun.tools.javac.comp.CompileStates;
 import com.sun.tools.javac.comp.Enter;
@@ -95,6 +96,7 @@
             Types.instance(this).newRound();
             Check.instance(this).newRound();
             Modules.instance(this).newRound();
+            Annotate.instance(this).newRound();
             CompileStates.instance(this).clear();
             MultiTaskListener.instance(this).clear();
 
--- a/langtools/test/tools/javac/modules/EdgeCases.java	Thu Jan 19 19:14:51 2017 -0800
+++ b/langtools/test/tools/javac/modules/EdgeCases.java	Fri Jan 20 09:26:49 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8154283 8167320
+ * @bug 8154283 8167320 8171098
  * @summary tests for multi-module mode compilation
  * @library /tools/lib
  * @modules
@@ -484,4 +484,58 @@
             throw new AssertionError("Unexpected output: " + log);
         }
     }
+
+    @Test
+    public void testOnDemandCompletionModuleInfoJava(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path src_m1 = src.resolve("m1x");
+        tb.writeJavaFiles(src_m1,
+                          "@Deprecated module m1x { }");
+        Path src_m2 = src.resolve("m2x");
+        tb.writeJavaFiles(src_m2,
+                          "module m2x { requires m1x; }");
+        Path src_m3 = src.resolve("m3x");
+        tb.writeJavaFiles(src_m3,
+                          "module m3x { requires m2x; requires m1x; }");
+        Path classes = base.resolve("classes");
+        tb.createDirectories(classes);
+
+        List<String> log;
+        List<String> expected;
+
+        log = new JavacTask(tb)
+                .options("--module-source-path", src.toString())
+                .outdir(classes)
+                .files(findJavaFiles(src_m1))
+                .run()
+                .writeAll()
+                .getOutputLines(Task.OutputKind.DIRECT);
+
+        expected = Arrays.asList("");
+
+        if (!expected.equals(log)) {
+            throw new IllegalStateException(log.toString());
+        }
+
+        log = new JavacTask(tb)
+                .options("--module-source-path", src.toString(),
+                         "-XDrawDiagnostics",
+                         "-Xlint:deprecation")
+                .outdir(classes)
+                .files(findJavaFiles(src_m3))
+                .run()
+                .writeAll()
+                .getOutputLines(Task.OutputKind.DIRECT);
+
+        expected = Arrays.asList(
+                "module-info.java:1:23: compiler.warn.has.been.deprecated.module: m1x",
+                "module-info.java:1:37: compiler.warn.has.been.deprecated.module: m1x",
+                "2 warnings"
+        );
+
+        if (!expected.equals(log)) {
+            throw new IllegalStateException(log.toString());
+        }
+    }
+
 }