eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
167 stars 131 forks source link

NPE when using `--release` with a JRE #3326

Closed snicoll closed 3 hours ago

snicoll commented 3 hours ago

You can reproduce the problem using https://github.com/snicoll-scratches/demo-jep247-jre. It has a README that explains the commands to invoke to reproduce. I have tried on various JRE distributions.

The TL;DR is that the Eclipse Compiler does not seem to support the use of --release when running in a JRE. Here's the combination that I tested:

When we opt-in for JRE 247 on a JRE that's more recent that the target release, the error is as follows:

java.lang.NullPointerException: Cannot invoke "java.nio.file.FileSystem.getPath(String, String[])" because "this.fs" is null
    at org.eclipse.jdt.internal.compiler.batch.ClasspathJep247Jdk12.findClass(ClasspathJep247Jdk12.java:96)
    at org.eclipse.jdt.internal.compiler.batch.ClasspathJsr199.findClass(ClasspathJsr199.java:83)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.internalFindClass(FileSystem.java:508)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.findClass(FileSystem.java:439)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.findType(FileSystem.java:598)
    at org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment.findType(IModuleAwareNameEnvironment.java:101)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPlainPackage(LookupEnvironment.java:1170)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:138)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:517)
    at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:875)
    at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:393)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:447)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:425)
    at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4710)
    at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.call(EclipseCompilerImpl.java:100)
    at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$1.call(EclipseCompiler.java:196)
    at com.example.demo.DemoJep247JreApplication.compile(DemoJep247JreApplication.java:37)
    at com.example.demo.DemoJep247JreApplication.main(DemoJep247JreApplication.java:104)

Debugging this happens when ClasspathJep247Jdk12 operates on the lib/jrt-fs.jar of the JRE distribution. I believe the FileSystem is not initialized as Path filePath = this.jdkHome.toPath().resolve("lib").resolve("ct.sym"); is not found.

Let me know if you need more details.

iloveeclipse commented 3 hours ago

AFAIK ct.sym is not a part of a JRE but JDK only, but it is essential to support --release option as it contains all the past API signatures. With that, you can't use JRE if you want use --release

snicoll commented 2 hours ago

Thanks for the quick feedback and I suspected as much. Don't you want to fix the NPE and provide something more meaningful to users?

iloveeclipse commented 2 hours ago

Could you please try the latest version from https://download.eclipse.org/eclipse/downloads/drops4/I20241119-0600/? The code is changed meanwhile (stack doesn't match current master), not sure f we handle it differently now.

snicoll commented 1 hour ago

With 3.40.0-SNAPSHOT (ecj-3.40.0-20241117.122305-150.jar specifically)

java.lang.NullPointerException: Cannot invoke "java.nio.file.FileSystem.getPath(String, String[])" because "this.fs" is null
    at org.eclipse.jdt.internal.compiler.batch.ClasspathJep247Jdk12.findClass(ClasspathJep247Jdk12.java:95)
    at org.eclipse.jdt.internal.compiler.batch.ClasspathJsr199.findClass(ClasspathJsr199.java:81)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.internalFindClass(FileSystem.java:512)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.findClass(FileSystem.java:443)
    at org.eclipse.jdt.internal.compiler.batch.FileSystem.findType(FileSystem.java:602)
    at org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment.findType(IModuleAwareNameEnvironment.java:100)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPlainPackage(LookupEnvironment.java:1177)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:145)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:524)
    at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:900)
    at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:415)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:469)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:447)
    at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4684)
    at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.call(EclipseCompilerImpl.java:98)
    at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$2.call(EclipseCompiler.java:196)
    at com.example.demo.DemoJep247JreApplication.compile(DemoJep247JreApplication.java:37)
    at com.example.demo.DemoJep247JreApplication.main(DemoJep247JreApplication.java:104)