Skip to content

Commit

Permalink
8321164: javac with annotation processor throws AssertionError: Filli…
Browse files Browse the repository at this point in the history
…ng jrt:/... during JarFileObject[/...]

Backport-of: 03c4595173d564df97aa4f2b3156adcd4be379fa
  • Loading branch information
shipilev committed Jan 16, 2024
1 parent 551855c commit f57f2cb
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -2398,20 +2398,26 @@ private Type erasure(Type t, boolean recurse) {
}
// where
private TypeMapping<Boolean> erasure = new StructuralTypeMapping<Boolean>() {
@SuppressWarnings("fallthrough")
private Type combineMetadata(final Type s,
final Type t) {
if (t.getMetadata().nonEmpty()) {
switch (s.getKind()) {
case OTHER:
case UNION:
case INTERSECTION:
case PACKAGE:
case EXECUTABLE:
case NONE:
case VOID:
case ERROR:
switch (s.getTag()) {
case CLASS:
if (s instanceof UnionClassType ||
s instanceof IntersectionClassType) {
return s;
}
//fall-through
case BYTE, CHAR, SHORT, LONG, FLOAT, INT, DOUBLE, BOOLEAN,
ARRAY, MODULE, TYPEVAR, WILDCARD, BOT:
return s.dropMetadata(Annotations.class);
case VOID, METHOD, PACKAGE, FORALL, DEFERRED,
NONE, ERROR, UNKNOWN, UNDETVAR, UNINITIALIZED_THIS,
UNINITIALIZED_OBJECT:
return s;
default: return s.dropMetadata(Annotations.class);
default:
throw new AssertionError(s.getTag().name());
}
} else {
return s;
Expand Down
118 changes: 118 additions & 0 deletions test/langtools/tools/javac/annotations/ReadingMethodWithTypeAnno.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8321164
* @summary Indirectly verify that types.erasure does not complete, called from
* ClassReader.isSameBinaryType, which must not complete.
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox
* @run main ReadingMethodWithTypeAnno
*/

import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import toolbox.JavacTask;
import toolbox.Task.Expect;
import toolbox.Task.OutputKind;
import toolbox.TestRunner;
import toolbox.ToolBox;

public class ReadingMethodWithTypeAnno extends TestRunner {
public static void main(String... args) throws Exception {
ReadingMethodWithTypeAnno r = new ReadingMethodWithTypeAnno();
r.runTests(m -> new Object[] { Paths.get(m.getName()) });
}

private final ToolBox tb = new ToolBox();

public ReadingMethodWithTypeAnno() throws IOException {
super(System.err);
}

@Test
public void test_DeclNone_UseNone(Path base) throws IOException {
Path libSrc = base.resolve("lib-src");
Path libClasses = Files.createDirectories(base.resolve("lib-classes"));

tb.writeJavaFiles(libSrc,
"""
public class Lib {
public void test(java.lang.@Ann String s) {
new Object() {};
}
}
""",
"""
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE_USE)
public @interface Ann {}
""");

new JavacTask(tb)
.outdir(libClasses)
.files(tb.findJavaFiles(libSrc))
.run(Expect.SUCCESS)
.writeAll()
.getOutput(OutputKind.DIRECT);

Path src = base.resolve("src");
Path classes = Files.createDirectories(base.resolve("classes"));

tb.writeJavaFiles(src,
"""
public class Test {
}
""");

new JavacTask(tb)
.outdir(classes)
.classpath(libClasses)
.files(tb.findJavaFiles(src))
.callback(task -> {
task.addTaskListener(new TaskListener() {
@Override
public void finished(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ENTER) {
task.getElements().getTypeElement("Lib");
task.getElements().getTypeElement("Lib$1");
}
}
});
})
.run(Expect.SUCCESS)
.writeAll()
.getOutput(OutputKind.DIRECT);
}

}

1 comment on commit f57f2cb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.