Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 535552

Summary: ecj requires module path to compile where javac doesn't
Product: [Eclipse Project] JDT Reporter: Philippe Cadé <philippe.cade>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: lars.schuetze, stephan.herrmann
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard: stalebug
Attachments:
Description Flags
Java code to compile and Ant build file none

Description Philippe Cadé CLA 2018-06-05 07:39:37 EDT
Created attachment 274333 [details]
Java code to compile and Ant build file

The --module-path=${java.home}/jmods option is necessary to compile code that uses an extra module when using ecj. This option is not required when using javac. I expect both javac and ecj to have the same behavior.

May be this is a follow up to bug #487421.

An example is attached: we're trying to compile Test.java with the given Ant file.

The compile-javac target uses the Java compiler. The only required option is to add the java.xml.bind module since we use JAXBException.

The compile-ecj target uses the same options but fails with "invalid module name java.xml.bind".

The compile-ecj-with-modulepath target adds the --module-path=${java.home}/jmods option and can compile the code without error.

The print-version-info gives this on my machine:

print-version-info:
     [echo] Java home is C:\Program Files\Java\jdk-10
     [echo] Java version is 10
     [echo] Ant version is Apache Ant(TM) version 1.10.3 compiled on March 24 2018
Comment 1 Stephan Herrmann CLA 2018-06-05 09:26:00 EDT
This works for me:

$ java -jar ecj-4.8RC3.jar -9 --add-modules java.xml.bind Test.java

However, when running ecj in the debugger I can see the reported failure.

First thing that looks fishy to me: Main.initRootModules() is only ever called, when this.compilerOptions.processAnnotations, so if an invocation passes -proc:none I would expect the --add-modules option to remain without effect. Surprisingly, when running ecj from a recent jar I don't see -proc:none having any impact on this issue.

OTOH, when running in the debugger and when I force initRootModules() to be invoked (by omitting -proc:none or by moving the invocation out of the if) I'm greeted by:

invalid module name: java.xml.bind


While I can't make hear or tails of these findings, it seems that Bug 525266 has a finger in the pie. 

@Jay?
Comment 2 Stephan Herrmann CLA 2018-12-06 13:52:54 EST
Back-link to the SO question where this was raised: https://stackoverflow.com/questions/50683168/how-to-compile-this-code-with-java-10-ant-and-the-eclipse-compiler
Comment 3 Eclipse Genie CLA 2020-11-26 12:33:55 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Philippe Cadé CLA 2020-11-27 05:52:08 EST
I suggest to close this as Java 10 is EOL and this situation is not really relevant to me anymore.

We learned to live with the javac/ecj differences.
Comment 5 Eclipse Genie CLA 2022-11-21 12:38:41 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Stephan Herrmann CLA 2022-11-25 18:40:59 EST
(In reply to Philippe Cadé from comment #4)
> I suggest to close this as Java 10 is EOL and this situation is not really
> relevant to me anymore.

right, in newer JDKs java.xml.bind is no longer present, so the bug cannot be reproduced any more.