Bug 574229 - ecj 3.26.0 + java 8 = java.lang.NoSuchFieldError: MODULE_SOURCE_PATH
Summary: ecj 3.26.0 + java 8 = java.lang.NoSuchFieldError: MODULE_SOURCE_PATH
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.20   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Andrey Loskutov CLA
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-06-16 04:35 EDT by Piotr Żygieło CLA
Modified: 2021-06-21 00:49 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Żygieło CLA 2021-06-16 04:35:52 EDT
On project built with maven, when upgrading from 3.25.0 to 3.26.0, using JDK8, I'm getting

> Caused by: java.lang.NoSuchFieldError: MODULE_SOURCE_PATH
>     at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.getCompilationUnits (EclipseCompilerImpl.java:153)
>     at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation (Main.java:4790)
>     at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.call (EclipseCompilerImpl.java:94)
>     at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$1.call (EclipseCompiler.java:196)
>     at org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler.performCompile (EclipseJavaCompiler.java:417)
>     at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1134)
>     at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:187)


I believe it's due to

https://github.com/eclipse/eclipse.jdt.core/blob/f1785daee4bc6e01623be6fc0e0047643df6a3e1/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java#L153

which uses https://docs.oracle.com/javase/9/docs/api/javax/tools/StandardLocation.html#MODULE_SOURCE_PATH - available only since 9.

I'm not sure of the version mapping from https://repo.maven.apache.org/maven2/org/eclipse/jdt/ecj/3.26.0 - so selecting the latest 4.21.
Comment 1 Piotr Żygieło CLA 2021-06-16 04:38:48 EDT
Seems related bug 545001
Comment 2 Piotr Żygieło CLA 2021-06-16 04:40:33 EDT
Seems to be introduced in bug 541269
Comment 3 Andrey Loskutov CLA 2021-06-16 05:53:57 EDT
While bug 541269 added the code in question, see also bug 573283 related to the general issue with "modern" javax API/classes used in ecj compiler.

We are using Java 9+ classes in ecj compiler that claims to support execution on Java 8, and it was a pure luck we didn't hit the problem before.

However, if I remove javax15api.jar from classpath, I see 55 compilation errors in EclipseCompiler, EclipseCompilerImpl, EclipseFileManager and ModuleLocationHandler. 

Of course not all of them are relevant if running ecj on Java 8 (callbacks that can be only called on Java 9+ are never called on Java 8).

It was just matter of time that a particular execution path would run into a problem on old JDK 8.

I think the code in querstion misses 
if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_8) > 0) guard.

But honestly, we should stop doing that - the code is extremely complicated already, without Java 8/9+ dancing, so we should stop supporting Java 8, see bug 572389.
Comment 4 Thomas Wolf CLA 2021-06-16 06:13:25 EDT
(In reply to Andrey Loskutov from comment #3)
> so we should stop supporting Java 8, see bug 572389.

That is *not* an option until --release 8 works properly. See bug 574181.
Comment 5 Andrey Loskutov CLA 2021-06-16 06:24:43 EDT
(In reply to Thomas Wolf from comment #4)
> (In reply to Andrey Loskutov from comment #3)
> > so we should stop supporting Java 8, see bug 572389.
> 
> That is *not* an option until --release 8 works properly. See bug 574181.

It *is* an option, for sure, if project decides to do so because it has no resources to maintain existing code. Bug 574181 is unrelated - it can be fixed with ecj running on Java 11.
Comment 6 Thomas Wolf CLA 2021-06-16 06:33:42 EDT
(In reply to Andrey Loskutov from comment #5)
> (In reply to Thomas Wolf from comment #4)
> > (In reply to Andrey Loskutov from comment #3)
> > > so we should stop supporting Java 8, see bug 572389.
> > 
> > That is *not* an option until --release 8 works properly. See bug 574181.
> 
> It *is* an option, for sure, if project decides to do so because it has no
> resources to maintain existing code. Bug 574181 is unrelated - it can be
> fixed with ecj running on Java 11.

Precisely not. If you need to generate code for a Java 8 target but run ECJ on Java 11, you can get calls to Java-11 only API generated. That's bug 574181. The work-around is to run ECJ on Java 8 when you have to generate code for Java 8. If ECJ doesn't support running on Java 8 anymore, you can't use it in a maven build to generate code for Java 8 unless --release 8 works properly.
Comment 7 Andrey Loskutov CLA 2021-06-16 06:43:40 EDT
(In reply to Thomas Wolf from comment #6)
> Precisely not. If you need to generate code for a Java 8 target but run ECJ
> on Java 11, you can get calls to Java-11 only API generated. That's bug
> 574181. The work-around is to run ECJ on Java 8 when you have to generate
> code for Java 8. If ECJ doesn't support running on Java 8 anymore, you can't
> use it in a maven build to generate code for Java 8 unless --release 8 works
> properly.

The project decides if ecj should continue to support running on Java 8 with the next release(s) or not. If there are no people left to maintain ecj, it is not a question "if" but "when" the support will be stopped.

Please note, one can always use older ecj version to compile on older Java releases or even switch to javac.

Note: this discussion should go either to bug 572389 or to bug 574181.
Comment 8 Sravan Kumar Lakkimsetti CLA 2021-06-19 10:52:21 EDT
Since JDT team decided to move to Java 11 with bug 572389,  closing this as won't Fix
Comment 9 Jay Arthanareeswaran CLA 2021-06-21 00:49:05 EDT
(In reply to Andrey Loskutov from comment #5)
> (In reply to Thomas Wolf from comment #4)
> > (In reply to Andrey Loskutov from comment #3)
> > > so we should stop supporting Java 8, see bug 572389.
> > 
> > That is *not* an option until --release 8 works properly. See bug 574181.
> 
> It *is* an option, for sure, if project decides to do so because it has no
> resources to maintain existing code. Bug 574181 is unrelated - it can be
> fixed with ecj running on Java 11.

Correct me if I am wrong. Is it only about --release 8? I am sure the issue remains when we use a different more recent release value, right? Which makes bug 574181 a must fix?