Warning: File for type '[Insert class here]' created in the last round will not be subject to annotation processing
java, java-7
Solution
In OpenJDK test case this warning produced because processor uses "processingOver()" to write new file exactly at last round.
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) {
if (renv.processingOver()) { // Write only at last round
Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager();
try {
JavaFileObject fo = filer.createSourceFile("Gen");
Writer out = fo.openWriter();
out.write("class Gen { }");
out.close();
messager.printMessage(Diagnostic.Kind.NOTE, "File 'Gen' created");
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, e.toString());
}
}
return false;
}
I modified original example code a bit. Added diagnostic note "File 'Gen' created", replaced "*" mask with "org.junit.runner.RunWith" and set return value to "true". Produced compiler log was:
Round 1:
input files: {ProcFileCreateLastRound}
annotations: [org.junit.runner.RunWith]
last round: false
Processor AnnoProc matches [org.junit.runner.RunWith] and returns true.
Round 2:
input files: {}
annotations: []
last round: true
Note: File 'Gen' created
Compilation completed successfully with 1 warning
0 errors
1 warning
Warning: File for type 'Gen' created in the last round will not be subject to annotation processing.
If we remove my custom note from log, it's hard to tell that file 'Gen' was actually created on 'Round 2' - last round. So, basic advice applies: if in doubt - add more logs.
Where is also a little bit of useful info on this page: http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html
Read section about "ANNOTATION PROCESSING" and try to get more info with compiler options: -XprintProcessorInfo Print information about which annotations a processor is asked to process. -XprintRounds Print information about initial and subsequent annotation processing rounds.
Problem
I switched an existing code base to Java 7 and I keep getting this warning: ``` warning: File for type '[Insert class here]' created in the last round will not be subject to annotation processing. ``` A quick search reveals that no one has hit this warning. It's not documented in the javac compiler source either: From OpenJDK\langtools\src\share\classes\com\sun\tools\javac\processing\JavacFiler.java ``` private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException { checkNameAndExistence(name, isSourceFile); Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT); JavaFileObject.Kind kind = (isSourceFile ? JavaFileObject.Kind.SOURCE : JavaFileObject.Kind.CLASS); JavaFileObject fileObject = fileManager.getJavaFileForOutput(loc, name, kind, null); checkFileReopening(fileObject, true); if (lastRound) // <-------------------------------TRIGGERS WARNING log.warning("proc.file.create.last.round", name); if (isSourceFile) aggregateGeneratedSourceNames.add(name); else aggregateGeneratedClassNames.add(name); openTypeNames.add(name); return new FilerOutputJavaFileObject(name, fileObject); } ``` What does this mean and what steps can I take to clear this warning? Thanks.