@Nullable
  @Override
  protected Sdk resolveProjectJdk(@NotNull WizardContext context) {
    JavaSdk javaSdkType = JavaSdk.getInstance();
    ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();

    // gradle older than 4.2.1 doesn't support new java the version number format like 9.0.1, see https://github.com/gradle/gradle/issues/2992
    Predicate<Sdk> sdkCondition = sdk -> {
      JavaSdkVersion v = javaSdkType.getVersion(sdk);
      return v != null && v.isAtLeast(JavaSdkVersion.JDK_1_6) && !v.isAtLeast(JavaSdkVersion.JDK_1_9) &&
             ExternalSystemJdkUtil.isValidJdk(sdk);
    };

    Sdk mostRecentSdk = jdkTable.getSdksOfType(javaSdkType).stream().filter(sdkCondition).max(javaSdkType.versionComparator()).orElse(null);
    if (mostRecentSdk != null) {
      return mostRecentSdk;
    }

    Set<String> existingPaths = Arrays.stream(jdkTable.getAllJdks())
                                      .map(sdk -> sdk.getHomePath())
                                      .collect(Collectors.toCollection(() -> CollectionFactory.createFilePathSet()));
    for (String javaHome : javaSdkType.suggestHomePaths()) {
      if (!existingPaths.contains(FileUtil.toCanonicalPath(javaHome))) {
        Sdk jdk = javaSdkType.createJdk(ObjectUtils.notNull(javaSdkType.suggestSdkName(null, javaHome), ""), javaHome);
        if (sdkCondition.test(jdk)) {
          ApplicationManager.getApplication().runWriteAction(() -> jdkTable.addJdk(jdk));
          return jdk;
        }
      }
    }

    Project project = context.getProject() != null ? context.getProject() : ProjectManager.getInstance().getDefaultProject();
    Pair<String, Sdk> sdkPair = ExternalSystemJdkUtil.getAvailableJdk(project);
    if (!ExternalSystemJdkUtil.USE_INTERNAL_JAVA.equals(sdkPair.first)) {
      return sdkPair.second;
    }

    return null;
  }
@Nullable
  @Override
  protected Sdk resolveProjectJdk(@NotNull WizardContext context)