Change in behavior of javax.tools.JavaCompiler in JDK 8 running with -proc:only ?

Jan Lahoda jan.lahoda at oracle.com
Wed Mar 12 13:58:35 UTC 2014


Hi Boaz,

Do I understand it correctly that the only difference between JDK 7 and 
JDK 8 in your usecase is the return value from CompilationTask.call()? 
In particular, your annotation processor is run and the same errors are 
reported under both JDK 7 and JDK 8?

The related difference (in a usecase similar to yours) between JDK 7 and 
JDK 8 that I was able to find is as follows. In JDK 7 javac "forgot" 
that it produced the errors, and acted as it they were not printed, and 
so returned the OK return code for -proc:only (and, as another 
consequence, printed the errors again for normal compilation). In JDK 8, 
javac properly keeps track of errors it produced, and consequently 
returns "EXIT_ERROR", which is then mapped to "false" return value of 
CompilationTask.call().

Jan

On 03/12/2014 11:00 AM, Boaz Nahum wrote:
> Thank you so much for your reply.
>
> The simplest file that fails to compile is like this:
>
> package wf.auto_testing_jsystem_tiny_test.tint_test;
>
> import amat.jsystem.bbs_params.annotation.BuildingBlock;
> import amat.jsystem.bbs_utils.infrastructure.BuildingBlockContext;
>
> public class TinyTest {
>
>      /**
>       * A dummy comment
>       */
>      @BuildingBlock
>      public static void loadBatchFromFile(BuildingBlockContext context,
> String batchPath) throws Exception {
>
>      }
> }
>
>
> one of the error messages  is:
>
> *     ....\TinyTest.java:4: error: package
> amat.jsystem.bbs_utils.infrastructure does not exist
> *
> *     import amat.jsystem.bbs_utils.infrastructure.BuildingBlockContext;
> *
> ^
>
> As I mentioned in my question, it is expected error, because we don't
> supply all the necessary compilation dependencies(we can't) .
>
> My question -again-, is That in JDK 7, it works perfect:
> The errors above are reported only via
> javax.tools.DiagnosticListener#report (not printed to the console)
> javax.tools.JavaCompiler.CompilationTask#*call returns true*.
>
> In JDK 8,
> Same errors are reported both via javax.tools.DiagnosticListener#report
> and are printed to the console,
> javax.tools.JavaCompiler.CompilationTask#*call returns false*.
>
> *In JDK 7*, If I omit '-proc:only', then I get the exact behavior *as
> JDK 8*, that why I'm wondering, *maybe JDK 8 somehow ignore '-proc:only'*
>
> Thank again
> Boaz
>
>
>
>
> On Tue, Mar 11, 2014 at 8:24 PM, Jonathan Gibbons
> <jonathan.gibbons at oracle.com <mailto:jonathan.gibbons at oracle.com>> wrote:
>
>     Boaz,
>
>     In JDK 8, javac is more aggressive about reporting errors (and
>     stopping the compilation) if the errors cannot be fixed by running
>     annotation processors. This should not be an issue if you are using
>     anno processors for generating code.
>
>     What sort of errors are you seeing in your compilation?
>
>     -- Jon
>
>
>     On 03/11/2014 08:27 AM, Boaz Nahum wrote:
>>     Hi
>>
>>     I hope some can give me hint how anlyse our probelms with JDK 8.
>>
>>     We use some code like this to do annotation processing (for
>>     generating code):
>>
>>                 JavaCompiler.CompilationTask task =
>>                     javaCompiler.getTask(null, fileManager,
>>     diagnostics, optionsAsList, null, compilationUnits);
>>
>>                 BuildingBlockParamProcessor processor = new
>>     BuildingBlockParamProcessor();
>>                 List<Processor> processors = new ArrayList<Processor>();
>>                 processors.add(processor);
>>                 task.setProcessors(processors);
>>     if(!task.call()){ .... }
>>
>>     The code we try to process won't be compile in regular environment
>>     - a lot of stuff is missing from classpath.
>>     But that is OK, we use '-proc:only' and we *thought* that this
>>     what allows us to ignore the errors.
>>
>>
>>     When we moved to JDK 8, the exact code fails,
>>     javax.tools.JavaCompiler.CompilationTask#call returns false.
>>
>>     *My question, is a possibilty that '-proc:only' is ignored in JDK 8 ?
>>     *
>>     *Or maybe there is by-design change regarding annotation
>>     processing that we need to be aware of ?
>>     *
>>     I want to mention that if the early EAP of JDK 8 , this code run
>>     without any problems.
>>
>>     (Moving to annotation processing during compilation is big effort
>>     for us)
>>
>>     Any tip/hint will be appreciatively accepted
>>
>>     Thanks
>>     Boaz
>>
>>
>>
>
>


More information about the compiler-dev mailing list