private static @Nullable Pair<String, Integer> getForkedJavacSdk(DiagnosticListener<? super JavaFileObject> diagnostic, ModuleChunk chunk, int targetLanguageLevel) {
    final Pair<JpsSdk<JpsDummyElement>, Integer> associatedSdk = getAssociatedSdk(chunk);
    boolean canRunAssociatedJavac = false;
    if (associatedSdk != null) {
      final int sdkVersion = associatedSdk.second;
      canRunAssociatedJavac = sdkVersion >= ExternalJavacProcess.MINIMUM_REQUIRED_JAVA_VERSION;
      if (isTargetReleaseSupported(sdkVersion, targetLanguageLevel)) {
        if (canRunAssociatedJavac) {
          return Pair.create(associatedSdk.first.getHomePath(), sdkVersion);
        }
      }
      else {
        LOG.warn("Target bytecode version " + targetLanguageLevel + " is not supported by SDK " + sdkVersion + " associated with module " + chunk.getName());
      }
    }

    final String fallbackJdkHome = System.getProperty(GlobalOptions.FALLBACK_JDK_HOME, null);
    if (fallbackJdkHome == null) {
      LOG.info("Fallback JDK is not specified. (See " + GlobalOptions.FALLBACK_JDK_HOME + " option)");
    }
    final String fallbackJdkVersion = System.getProperty(GlobalOptions.FALLBACK_JDK_VERSION, null);
    if (fallbackJdkVersion == null) {
      LOG.info("Fallback JDK version is not specified. (See " + GlobalOptions.FALLBACK_JDK_VERSION + " option)");
    }

    if (associatedSdk == null && (fallbackJdkHome == null || fallbackJdkVersion == null)) {
      diagnostic.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, JpsBuildBundle.message("build.message.cannot.start.javac.process.for.0.unknown.jdk.home", chunk.getName())));
      return null;
    }

    // either associatedSdk or fallbackJdk is configured, but associatedSdk cannot be used
    if (fallbackJdkHome != null) {
      final int fallbackVersion = JpsJavaSdkType.parseVersion(fallbackJdkVersion);
      if (isTargetReleaseSupported(fallbackVersion, targetLanguageLevel)) {
        if (fallbackVersion >= ExternalJavacProcess.MINIMUM_REQUIRED_JAVA_VERSION) {
          return Pair.create(fallbackJdkHome, fallbackVersion);
        }
        else {
          LOG.info("Version string for fallback JDK is '" + fallbackJdkVersion + "' (recognized as version '" + fallbackVersion + "')." +
                   " At least version " + ExternalJavacProcess.MINIMUM_REQUIRED_JAVA_VERSION + " is required to launch javac process.");
        }
      }
    }

    // at this point, fallbackJdk is not suitable too
    if (associatedSdk != null) {
      if (canRunAssociatedJavac) {
        // although target release is not supported, attempt to start javac, so that javac properly reports this error
        return Pair.create(associatedSdk.first.getHomePath(), associatedSdk.second);
      }
      else {
        diagnostic.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR,
          JpsBuildBundle.message(
            "build.message.unsupported.javac.version",
            chunk.getName(),
            associatedSdk.second,
            ExternalJavacProcess.MINIMUM_REQUIRED_JAVA_VERSION,
            targetLanguageLevel
          )
        ));
      }
    }

    return null;
  }
private static @Nullable Pair<String, Integer> getForkedJavacSdk(DiagnosticListener<? super JavaFileObject> diagnostic, ModuleChunk chunk, int targetLanguageLevel)