changeset 43143:a8f5cdfa330a

8171528: Crash in Annotate with duplicate package-info declarations Reviewed-by: jjg
author vromero
date Thu, 12 Jan 2017 15:59:28 -0800
parents e72c3d9b0a0b
children b5e41646e1a6
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java langtools/test/tools/javac/T8171528/DuplicatedAnnotatedPackagesTest.java langtools/test/tools/javac/T8171528/DuplicatedAnnotatedPackagesTest.out langtools/test/tools/javac/T8171528/pkg1/package-info.java langtools/test/tools/javac/T8171528/pkg2/package-info.java
diffstat 5 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Thu Jan 12 09:04:16 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Thu Jan 12 15:59:28 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -47,6 +47,7 @@
 import static com.sun.tools.javac.code.Flags.SYNTHETIC;
 import static com.sun.tools.javac.code.Kinds.Kind.MDL;
 import static com.sun.tools.javac.code.Kinds.Kind.MTH;
+import static com.sun.tools.javac.code.Kinds.Kind.PCK;
 import static com.sun.tools.javac.code.Kinds.Kind.VAR;
 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
 import static com.sun.tools.javac.code.TypeTag.ARRAY;
@@ -228,7 +229,14 @@
         s.resetAnnotations(); // mark Annotations as incomplete for now
 
         normal(() -> {
-            Assert.check(s.annotationsPendingCompletion());
+            // Packages are unusual, in that they are the only type of declaration that can legally appear
+            // more than once in a compilation, and in all cases refer to the same underlying symbol.
+            // This means they are the only kind of declaration that syntactically may have multiple sets
+            // of annotations, each on a different package declaration, even though that is ultimately
+            // forbidden by JLS 8 section 7.4.
+            // The corollary here is that all of the annotations on a package symbol may have already
+            // been handled, meaning that the set of annotations pending completion is now empty.
+            Assert.check(s.kind == PCK || s.annotationsPendingCompletion());
             JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
             DiagnosticPosition prevLintPos =
                     deferPos != null
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171528/DuplicatedAnnotatedPackagesTest.java	Thu Jan 12 15:59:28 2017 -0800
@@ -0,0 +1,6 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 8171528
+ * @summary Crash in Annotate with duplicate package-info declarations
+ * @compile/fail/ref=DuplicatedAnnotatedPackagesTest.out -XDrawDiagnostics pkg1/package-info.java pkg2/package-info.java
+ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171528/DuplicatedAnnotatedPackagesTest.out	Thu Jan 12 15:59:28 2017 -0800
@@ -0,0 +1,4 @@
+package-info.java:2:9: compiler.warn.pkg-info.already.seen: test
+package-info.java:1:1: compiler.err.already.annotated: kindname.package, test
+1 error
+1 warning
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171528/pkg1/package-info.java	Thu Jan 12 15:59:28 2017 -0800
@@ -0,0 +1,2 @@
+@Deprecated
+package test;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171528/pkg2/package-info.java	Thu Jan 12 15:59:28 2017 -0800
@@ -0,0 +1,2 @@
+@Deprecated
+package test;