8171098: NPE when --add-modules java.corba is used

Block annotations queue until enter is done, to avoid flushing annotations during module resolution.

Reviewed-by: jjg
This commit is contained in:
Jan Lahoda 2017-01-20 09:26:49 +01:00
parent 04405c6abc
commit ec3981561d
9 changed files with 95 additions and 14 deletions

View File

@ -118,6 +118,8 @@ public class Annotate {
Source source = Source.instance(context);
allowRepeatedAnnos = source.allowRepeatedAnnotations();
sourceName = source.name;
blockCount = 1;
}
/** Semaphore to delay annotation processing */
@ -144,6 +146,10 @@ public class Annotate {
/** 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 class Annotate {
}
};
}
public void newRound() {
blockCount = 1;
}
}

View File

@ -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 @@ public class JavaCompiler {
**/
protected boolean implicitSourceFilesRead;
protected boolean enterDone;
private boolean enterDone;
protected CompileStates compileStates;
@ -1042,7 +1042,7 @@ public class JavaCompiler {
public List<JCCompilationUnit> initModules(List<JCCompilationUnit> roots) {
modules.initModules(roots);
if (roots.isEmpty()) {
enterDone = true;
enterDone();
}
return roots;
}
@ -1063,7 +1063,7 @@ public class JavaCompiler {
enter.main(roots);
enterDone = true;
enterDone();
if (!taskListener.isEmpty()) {
for (JCCompilationUnit unit: roots) {
@ -1725,6 +1725,11 @@ public class JavaCompiler {
}
}
public void enterDone() {
enterDone = true;
annotate.enterDone();
}
public boolean isEnterDone() {
return enterDone;
}

View File

@ -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 com.sun.tools.javac.util.Options;
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
compiler.newRound();
modules.newRound();
types.newRound();
annotate.newRound();
boolean foundError = false;

View File

@ -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.JCDiagnostic.DiagnosticPosition;
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 @@ public class JavadocEnter extends Enter {
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;
}

View File

@ -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 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
// 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)

View File

@ -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.JCDiagnostic.DiagnosticPosition;
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 @@ public class JavadocEnter extends Enter {
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;
}

View File

@ -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 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
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);

View File

@ -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;
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 @@ class ReusableContext extends Context implements TaskListener {
Types.instance(this).newRound();
Check.instance(this).newRound();
Modules.instance(this).newRound();
Annotate.instance(this).newRound();
CompileStates.instance(this).clear();
MultiTaskListener.instance(this).clear();

View File

@ -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 @@ public class EdgeCases extends ModuleTestBase {
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());
}
}
}