Skip to content

Unexpected "JRE container" entry derived from pom.xml for Java SE 13 #951

Closed

Description

@anthonyvdotbe

When opening a Maven project which uses maven.compiler.source/target 13, the derived .classpath file uses J2SE-1.5 as its JRE container, instead of the expected JavaSE-12.

In other words: if the value for the Maven compiler properties is unsupported/unrecognized, it should default to the highest currently-supported version. This is much more likely to be what the user wants/expects. For example, with the new JDK release cadence (the first JDK 14 build is already released), it's more common (for me at least) to try out early-access JDK builds.

Environment
  • Operating System: Windows 10 Pro 1809 (17763.557)
  • JDK version: 12.0.1
  • Visual Studio Code version: 1.35.1
  • Java extension version: 0.46.0
Steps To Reproduce
  1. unzip and open sample-maven-project.zip
  2. let the extension generate the project files
Current Result

The .classpath file contains the following:

	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
Expected Result

The .classpath file contains the following:

	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>

Activity

  1. self-assigned this
    on Jun 20, 2019
  2. added this to the Mid July 2019 milestone on Jun 20, 2019
  3. fbricon commented on Jul 16, 2019

    @fbricon
    Collaborator
  4. fbricon commented on Jul 16, 2019

    @fbricon
    Collaborator

    The fixed m2e version is now consumed by jdt.ls (eclipse-jdtls/eclipse.jdt.ls@c966395)

  5. EricZhangzf commented on Jul 18, 2019

    @EricZhangzf

    Test this issue in my local machine, No matter what my local jdk version is(1.8, 11, 12), The .classpath file always:

    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12">
          <attributes>
                <attribute name="maven.pomderived" value="true"/>
          </attributes>
    </classpathentry>
    
  6. fbricon commented on Jul 18, 2019

    @fbricon
    Collaborator

    Ok, I think I know what the issue is. We select the highest execution environment, but there might not be an actual jdk backing it.

  7. removed this from the End August 2019 milestone on Sep 2, 2019
  8. removed their assignment
    on Jul 23, 2026
  9. robstryker commented on Nov 2, 2026

    @robstryker
    Contributor

    Already fixed upstream!

    Found it exactly where Fred's hunch pointed.

    org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java, method getExecutionEnvironment(String environmentId).

    Before the fix, the lookup was just an ID match with no viability check:

      for (IExecutionEnvironment environment : manager.getExecutionEnvironments()) {
          if (environment.getId().equals(environmentId)) {
              return environment;
          }
      }
      return null;
    

    So m2e would happily select e.g. JavaSE-12 purely because the ID matched the Maven compiler target, even if there was no actual installed JDK bound to that environment — exactly fbricon's diagnosis: "we select the highest execution environment, but there might not be an actual jdk backing it."

    The fix — commit aa212c49, Oct 11 2022, Konrad Windszus + Hannes Wellmann, closing m2e#842 ("Only select ExecutionEnvironments with at least one compatible VM installed"):

      IExecutionEnvironment environment = manager.getEnvironment(environmentId);
      if (environment != null && environment.getCompatibleVMs().length > 0) {
          return environment;
      }
      log.error("Failed to find a compatible VM for environment id '{}', falling back to workspace default", environmentId);
      return null;
    

    Now, when the chosen EE has zero compatible VMs, it falls back to null — which addJREClasspathContainer() turns into JavaRuntime.newDefaultJREContainerPath() (the workspace default JRE) instead of silently emitting a classpath entry for an environment with nothing backing it.

    Closing as fixed upstream.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions