Skip to content

Instantly share code, notes, and snippets.

@talios
Created June 8, 2012 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talios/2893027 to your computer and use it in GitHub Desktop.
Save talios/2893027 to your computer and use it in GitHub Desktop.
Javac Compiler Bug...
Potential bug in JavaC. Surely the line should be:
annotationProcessingOccurred = c.annotationProcessingOccurred == true;
and do a comparison instead of multi-assignment ( and only assign it if annotationProcessingOccurred is current false, as I don't think we want to reassign a true setting to false here).
Open JDK 6:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/tools/javac/main/JavaCompiler.java#JavaCompiler
995 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
996 if (c != this)
997 annotationProcessingOccurred = c.annotationProcessingOccurred = true;
998 return c;
Open JDK 7
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/com/sun/tools/javac/main/JavaCompiler.java?av=f
1106 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
1107 if (c != this)
1108 annotationProcessingOccurred = c.annotationProcessingOccurred = true;
1109 // doProcessing will have handled deferred diagnostics
1110 Assert.check(c.log.deferDiagnostics == false
1111 && c.log.deferredDiagnostics.size() == 0);
1112 return c;'
@rspilker
Copy link

rspilker commented Jun 8, 2012

If what you state is correct the line should either be
annotationProcessingOccurred = c.annotationProcessingOccurred;
or
annotationProcessingOccurred |= c.annotationProcessingOccurred;

@talios
Copy link
Author

talios commented Jun 8, 2012

The later is my current guess after thinking about it more, of course - I don't know WHY you'd have multiple instances of a javaCompiler so this might not actually be a problem. I have an odd thought that when annotation processing occurs, another javaCompiler instance is possibly created to compile any generated sources, which would mean the code here is probably correct - but kinda smelly code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment