23
23
24
24
/*
25
25
* @test
26
- * @bug 8310061 8315534
27
- * @summary Verify a note is issued for implicit annotation processing
26
+ * @bug 8310061 8315534 8306819
27
+ * @summary Verify behavior around implicit annotation processing
28
28
*
29
29
* @library /tools/lib /tools/javac/lib
30
30
* @modules
59
59
import toolbox .JarTask ;
60
60
61
61
/*
62
- * Generates note and the processor runs :
62
+ * Does not generates a note and the processor does not run :
63
63
* $ javac -cp ImplicitProcTestProc.jar HelloWorldTest.java
64
64
*
65
- * Does _not_ generate a note and the processor runs :
65
+ * Does _not_ generate a note and the processor does run :
66
66
* $ javac -processorpath ImplicitProcTestProc.jar HelloWorldTest.java
67
67
* $ javac -cp ImplicitProcTestProc.jar -processor ImplicitProcTestProc.jar HelloWorldTest.java
68
68
* $ javac -cp ImplicitProcTestProc.jar -proc:full HelloWorldTest.java
69
69
* $ javac -cp ImplicitProcTestProc.jar -proc:only HelloWorldTest.java
70
+ *
71
+ * Does _not_ generate a note and the processor does _not_run:
70
72
* $ javac -cp ImplicitProcTestProc.jar -Xlint:-options HelloWorldTest.java
71
73
* $ javac -cp ImplicitProcTestProc.jar -Xlint:none HelloWorldTest.java
72
74
*
73
75
* Does _not_ generate a note and the processor _doesn't_ run.
74
76
* $ javac -cp ImplicitProcTestProc.jar -proc:none HelloWorldTest.java
77
+ *
78
+ * (Previously, annotation processing was implicitly enabled and the
79
+ * the class path was searched for processors. This test was
80
+ * originally written to probe around a note warning of a potential
81
+ * future policy change to disable such implicit processing, a policy
82
+ * change now implemented and this test has been updated accordingly.)
75
83
*/
76
84
77
85
public class TestNoteOnImplicitProcessing extends TestRunner {
@@ -165,8 +173,8 @@ public void generateWarning(Path base, Path jarFile) {
165
173
.run (Expect .SUCCESS )
166
174
.writeAll ();
167
175
168
- checkForProcessorMessage (javacResult , true );
169
- checkForCompilerNote (javacResult , true );
176
+ checkForProcessorMessage (javacResult , false );
177
+ checkForCompilerNote (javacResult , false );
170
178
}
171
179
172
180
@ Test
@@ -239,7 +247,7 @@ public void lintOptions(Path base, Path jarFile) {
239
247
.run (Expect .SUCCESS )
240
248
.writeAll ();
241
249
242
- checkForProcessorMessage (javacResult , true );
250
+ checkForProcessorMessage (javacResult , false );
243
251
checkForCompilerNote (javacResult , false );
244
252
}
245
253
@@ -254,7 +262,7 @@ public void lintNone(Path base, Path jarFile) {
254
262
.run (Expect .SUCCESS )
255
263
.writeAll ();
256
264
257
- checkForProcessorMessage (javacResult , true );
265
+ checkForProcessorMessage (javacResult , false );
258
266
checkForCompilerNote (javacResult , false );
259
267
}
260
268
@@ -317,7 +325,7 @@ public void processorsViaAPI(Path base, Path jarFile) throws Exception {
317
325
318
326
task .call ();
319
327
320
- verifyMessages (out , compilerOut , true );
328
+ verifyMessages (out , compilerOut , false , false );
321
329
}
322
330
323
331
{
@@ -329,7 +337,7 @@ public void processorsViaAPI(Path base, Path jarFile) throws Exception {
329
337
task .setProcessors (List .of (processor ));
330
338
task .call ();
331
339
332
- verifyMessages (out , compilerOut , false );
340
+ verifyMessages (out , compilerOut , false , true );
333
341
}
334
342
335
343
{
@@ -339,7 +347,7 @@ public void processorsViaAPI(Path base, Path jarFile) throws Exception {
339
347
340
348
task .analyze ();
341
349
342
- verifyMessages (out , compilerOut , true );
350
+ verifyMessages (out , compilerOut , false , false );
343
351
}
344
352
345
353
{
@@ -353,16 +361,21 @@ public void processorsViaAPI(Path base, Path jarFile) throws Exception {
353
361
task .setProcessors (List .of (processor ));
354
362
task .analyze ();
355
363
356
- verifyMessages (out , compilerOut , false );
364
+ verifyMessages (out , compilerOut , false , true );
357
365
}
358
366
} finally {
359
367
System .setOut (oldOut );
360
368
}
361
369
}
362
370
363
- private void verifyMessages (ByteArrayOutputStream out , StringWriter compilerOut , boolean expectedNotePresent ) {
364
- if (!out .toString (StandardCharsets .UTF_8 ).contains ("ImplicitProcTestProc run" )) {
365
- throw new RuntimeException ("Expected processor message not printed" );
371
+ private void verifyMessages (ByteArrayOutputStream out , StringWriter compilerOut , boolean expectedNotePresent ,
372
+ boolean processorRunExpected ) {
373
+ boolean processorRun = out .toString (StandardCharsets .UTF_8 ).contains ("ImplicitProcTestProc run" );
374
+
375
+ if (processorRun != processorRunExpected ) {
376
+ throw new RuntimeException (processorRunExpected ?
377
+ "Expected processor message not printed" :
378
+ "Unexpected processor message printed" );
366
379
}
367
380
368
381
out .reset ();
0 commit comments