Skip to content

Commit b6c9232

Browse files
committed
8305225: A service broken error despite annotation processor generating it if directives listed
Reviewed-by: asotona
1 parent 05fb6c6 commit b6c9232

File tree

2 files changed

+94
-3
lines changed

2 files changed

+94
-3
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1094,6 +1094,9 @@ public void visitProvides(JCProvides tree) {
10941094
} finally {
10951095
env.info.visitingServiceImplementation = prevVisitingServiceImplementation;
10961096
}
1097+
if (!it.hasTag(CLASS)) {
1098+
continue;
1099+
}
10971100
ClassSymbol impl = (ClassSymbol) it.tsym;
10981101
if ((impl.flags_field & PUBLIC) == 0) {
10991102
log.error(implName.pos(), Errors.NotDefPublic(impl, impl.location()));

test/langtools/tools/javac/modules/AnnotationProcessing.java

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @test
26-
* @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747 8236842 8254023 8263432
26+
* @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747 8236842 8254023 8263432 8305225
2727
* @summary Verify that annotation processing works.
2828
* @library /tools/lib
2929
* @modules
@@ -2133,6 +2133,94 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
21332133

21342134
}
21352135

2136+
@Test
2137+
public void testCreateProvidesWithAP(Path base) throws Exception {
2138+
Path src = base.resolve("src");
2139+
Path m1 = src.resolve("m");
2140+
2141+
tb.writeJavaFiles(m1,
2142+
"""
2143+
module m {
2144+
provides api1.Api with test.Test;
2145+
uses api1.Api;
2146+
uses api2.Api;
2147+
}
2148+
""");
2149+
2150+
Path classes = base.resolve("classes");
2151+
Files.createDirectories(classes);
2152+
2153+
List<String> expectedErrors = List.of(
2154+
"module-info.java:2:18: compiler.err.doesnt.exist: api1",
2155+
"module-info.java:2:32: compiler.err.doesnt.exist: test",
2156+
"module-info.java:3:14: compiler.err.doesnt.exist: api1",
2157+
"module-info.java:4:14: compiler.err.doesnt.exist: api2",
2158+
"4 errors");
2159+
List<String> actualErrors = new JavacTask(tb)
2160+
.options("-XDrawDiagnostics")
2161+
.outdir(classes)
2162+
.files(findJavaFiles(m1))
2163+
.run(Task.Expect.FAIL)
2164+
.writeAll()
2165+
.getOutputLines(OutputKind.DIRECT);
2166+
2167+
tb.checkEqual(expectedErrors, actualErrors);
2168+
2169+
new JavacTask(tb)
2170+
.options("-processor", CreateProvidesWithAP.class.getName())
2171+
.outdir(classes)
2172+
.files(findJavaFiles(m1))
2173+
.run()
2174+
.writeAll();
2175+
}
2176+
2177+
@SupportedAnnotationTypes("*")
2178+
public static final class CreateProvidesWithAP extends AbstractProcessor {
2179+
2180+
int round;
2181+
2182+
@Override
2183+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
2184+
processingEnv.getElementUtils().getModuleElement("m").getDirectives();
2185+
if (round++ == 0) {
2186+
try (Writer w = processingEnv.getFiler().createSourceFile("test.Test").openWriter()) {
2187+
w.append("""
2188+
package test;
2189+
public class Test implements api1.Api {
2190+
}
2191+
""");
2192+
} catch (IOException ex) {
2193+
throw new IllegalStateException(ex);
2194+
}
2195+
try (Writer w = processingEnv.getFiler().createSourceFile("api1.Api").openWriter()) {
2196+
w.append("""
2197+
package api1;
2198+
public interface Api {
2199+
}
2200+
""");
2201+
} catch (IOException ex) {
2202+
throw new IllegalStateException(ex);
2203+
}
2204+
try (Writer w = processingEnv.getFiler().createSourceFile("api2.Api").openWriter()) {
2205+
w.append("""
2206+
package api2;
2207+
public interface Api {
2208+
}
2209+
""");
2210+
} catch (IOException ex) {
2211+
throw new IllegalStateException(ex);
2212+
}
2213+
}
2214+
return false;
2215+
}
2216+
2217+
@Override
2218+
public SourceVersion getSupportedSourceVersion() {
2219+
return SourceVersion.latest();
2220+
}
2221+
2222+
}
2223+
21362224
private static void assertNonNull(String msg, Object val) {
21372225
if (val == null) {
21382226
throw new AssertionError(msg);

0 commit comments

Comments
 (0)