diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JvmConfigurator.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JvmConfigurator.java index 0376f4f2..e784fda8 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JvmConfigurator.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JvmConfigurator.java @@ -165,7 +165,7 @@ public IVMInstall configureVMInstall(java.nio.file.Path resolvedJavaHomePath, Ba getPrefix(vmType), resolvedJavaHomePath.getFileName().toString(), bazelWorkspace.getName()); - var vm = findVmForNameOrPath(resolvedJavaHomePath, name); + var vm = findVmForNameOrPath(resolvedJavaHomePath, name, bazelWorkspace, vmType); // delete if location or other attributes don't not match if ((vm instanceof AbstractVMInstall realVm) && (!vm.getInstallLocation().toPath().equals(resolvedJavaHomePath) @@ -239,12 +239,19 @@ private void enablePreviewIfPossible(IJavaProject javaProject, String version) { } } - private IVMInstall findVmForNameOrPath(java.nio.file.Path javaHome, String name) { + private IVMInstall findVmForNameOrPath(java.nio.file.Path javaHome, String name, BazelWorkspace bazelWorkspace, + String vmType) { var file = javaHome.toFile(); var types = JavaRuntime.getVMInstallTypes(); for (IVMInstallType type : types) { var installs = type.getVMInstalls(); for (IVMInstall install : installs) { + if (!(install instanceof AbstractVMInstall realVm) + || !bazelWorkspace.getLocation().toString().equals(realVm.getAttribute(VM_ATTR_WORKSPACE)) + || !vmType.equals(realVm.getAttribute(VM_ATTR_TYPE))) { + continue; + } + if ((name != null) && name.equals(install.getName())) { return install; }