mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-16 17:14:41 +02:00
8306819: Consider disabling the compiler's default active annotation processing
Reviewed-by: vromero
This commit is contained in:
parent
a4e9168bab
commit
dc4bc4f084
5 changed files with 46 additions and 38 deletions
|
@ -23,8 +23,8 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8310061 8315534
|
||||
* @summary Verify a note is issued for implicit annotation processing
|
||||
* @bug 8310061 8315534 8306819
|
||||
* @summary Verify behavior around implicit annotation processing
|
||||
*
|
||||
* @library /tools/lib /tools/javac/lib
|
||||
* @modules
|
||||
|
@ -59,19 +59,27 @@ import toolbox.ToolBox;
|
|||
import toolbox.JarTask;
|
||||
|
||||
/*
|
||||
* Generates note and the processor runs:
|
||||
* Does not generates a note and the processor does not run:
|
||||
* $ javac -cp ImplicitProcTestProc.jar HelloWorldTest.java
|
||||
*
|
||||
* Does _not_ generate a note and the processor runs:
|
||||
* Does _not_ generate a note and the processor does run:
|
||||
* $ javac -processorpath ImplicitProcTestProc.jar HelloWorldTest.java
|
||||
* $ javac -cp ImplicitProcTestProc.jar -processor ImplicitProcTestProc.jar HelloWorldTest.java
|
||||
* $ javac -cp ImplicitProcTestProc.jar -proc:full HelloWorldTest.java
|
||||
* $ javac -cp ImplicitProcTestProc.jar -proc:only HelloWorldTest.java
|
||||
*
|
||||
* Does _not_ generate a note and the processor does _not_run:
|
||||
* $ javac -cp ImplicitProcTestProc.jar -Xlint:-options HelloWorldTest.java
|
||||
* $ javac -cp ImplicitProcTestProc.jar -Xlint:none HelloWorldTest.java
|
||||
*
|
||||
* Does _not_ generate a note and the processor _doesn't_ run.
|
||||
* $ javac -cp ImplicitProcTestProc.jar -proc:none HelloWorldTest.java
|
||||
*
|
||||
* (Previously, annotation processing was implicitly enabled and the
|
||||
* the class path was searched for processors. This test was
|
||||
* originally written to probe around a note warning of a potential
|
||||
* future policy change to disable such implicit processing, a policy
|
||||
* change now implemented and this test has been updated accordingly.)
|
||||
*/
|
||||
|
||||
public class TestNoteOnImplicitProcessing extends TestRunner {
|
||||
|
@ -165,8 +173,8 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
.run(Expect.SUCCESS)
|
||||
.writeAll();
|
||||
|
||||
checkForProcessorMessage(javacResult, true);
|
||||
checkForCompilerNote(javacResult, true);
|
||||
checkForProcessorMessage(javacResult, false);
|
||||
checkForCompilerNote(javacResult, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -239,7 +247,7 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
.run(Expect.SUCCESS)
|
||||
.writeAll();
|
||||
|
||||
checkForProcessorMessage(javacResult, true);
|
||||
checkForProcessorMessage(javacResult, false);
|
||||
checkForCompilerNote(javacResult, false);
|
||||
}
|
||||
|
||||
|
@ -254,7 +262,7 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
.run(Expect.SUCCESS)
|
||||
.writeAll();
|
||||
|
||||
checkForProcessorMessage(javacResult, true);
|
||||
checkForProcessorMessage(javacResult, false);
|
||||
checkForCompilerNote(javacResult, false);
|
||||
}
|
||||
|
||||
|
@ -317,7 +325,7 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
|
||||
task.call();
|
||||
|
||||
verifyMessages(out, compilerOut, true);
|
||||
verifyMessages(out, compilerOut, false, false);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -329,7 +337,7 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
task.setProcessors(List.of(processor));
|
||||
task.call();
|
||||
|
||||
verifyMessages(out, compilerOut, false);
|
||||
verifyMessages(out, compilerOut, false, true);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -339,7 +347,7 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
|
||||
task.analyze();
|
||||
|
||||
verifyMessages(out, compilerOut, true);
|
||||
verifyMessages(out, compilerOut, false, false);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -353,16 +361,21 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
|
|||
task.setProcessors(List.of(processor));
|
||||
task.analyze();
|
||||
|
||||
verifyMessages(out, compilerOut, false);
|
||||
verifyMessages(out, compilerOut, false, true);
|
||||
}
|
||||
} finally {
|
||||
System.setOut(oldOut);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyMessages(ByteArrayOutputStream out, StringWriter compilerOut, boolean expectedNotePresent) {
|
||||
if (!out.toString(StandardCharsets.UTF_8).contains("ImplicitProcTestProc run")) {
|
||||
throw new RuntimeException("Expected processor message not printed");
|
||||
private void verifyMessages(ByteArrayOutputStream out, StringWriter compilerOut, boolean expectedNotePresent,
|
||||
boolean processorRunExpected) {
|
||||
boolean processorRun = out.toString(StandardCharsets.UTF_8).contains("ImplicitProcTestProc run");
|
||||
|
||||
if (processorRun != processorRunExpected) {
|
||||
throw new RuntimeException(processorRunExpected ?
|
||||
"Expected processor message not printed" :
|
||||
"Unexpected processor message printed");
|
||||
}
|
||||
|
||||
out.reset();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue