IJ19: myProjectJavaSdks fromProjectDescriptor is empty the first time

I am running into a strange problem after upgrading our plugin from IJ17 to  IJ19 and Java8 to Java11.

We have a builder that has the following code:

ProjectDescriptor descriptor = context.getCompileContext().getProjectDescriptor();
Set<JpsSdk<?>> sdks = descriptor.getProjectJavaSdks();

But the first time we start our instance of IntelliJ (It is Studio IDE based on top of IntelliJ), and try to rebuild the project, the sdks is empty. And this happens about 5 out of 10 times and not every time. When rebuilt again, everything compiles. 

The cause seem to be the null VersionString. The following returns null

module.getSdk(JpsJavaSdkType.INSTANCE).getVersionString()

which leads to this sdk not been added to myProjectJavaSdks in ProjectDescriptor.java

if (sdk != null && !myProjectJavaSdks.contains(sdk) && sdk.getVersionString() != null && sdk.getHomePath() != null) {
myProjectJavaSdks.add(sdk);
}

This problem happens the first time or after running cleanIdea and starting the IDE and running compile. 

Tried debugging but does not happen at all during debugging. So may be it is a timing issue / a thread not able to update stuff before the other one reads it. 

 

I have spent a lot of time on this. Any help will be appreciated.

This worked fine in IJ17 and Java8.

0
4 comments

May be something related to the following commit? I do not have permissions to see the bug details though

ProjectJdkTableImpl: build: force save for jdk.table.xml only before starting build (IDEA-CR-29179)
0

 

in jdk.table.xml <version value="java version &quot;11.0.1&quot;" /> is not set as the ide instance / rebuild starts. It gets set.. but too late probably

  <component name="ProjectJdkTable">

    <jdk version="2">

      <name value="11 (2)" />

      <type value="JavaSDK" />

      <version value="java version &quot;11.0.1&quot;" />

      <homePath value="/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home" />


When the Sdk is created at the beginning, the following is the SDK that is created. It does not have the versionString. 

 

 

But if I stop here and check sdk.getVersionString() in the Expression Evaluator, then it gets the versionString and shows it and is used to persist to jdk.table.xml later and things work 

0

And the compilation works i.e. the versionString is set in the jdk.table.xml if before running the compile process, any dialog like settings is opened.

 

In my code I am using the following:

public static Sdk createJavaSdk(final String javaHome) {
final Sdk[] result = new Sdk[1];
ApplicationManager.getApplication().invokeAndWait(() ->
result[0] = SdkConfigurationUtil.createAndAddSDK(javaHome, JavaSdk.getInstance()));
return result[0];
}

I also tried with ModalityState.NON_MODAL but does not help

0

Thanks for your report, we're investigating

0

Please sign in to leave a comment.