@Nullable
  public static TargetDebuggerConnection prepareDebuggerConnection(@NotNull JavaCommandLineState javaCommandLineState,
                                                                   @NotNull TargetEnvironmentRequest request) {
    final int remotePort;
    JavaParameters javaParameters;
    try {
      javaParameters = javaCommandLineState.getJavaParameters();
    } catch (ExecutionException e){
      return null;
    }

    {
      Integer remotePort2 = requiredDebuggerTargetPort(javaCommandLineState, request);
      if (remotePort2 == null) {
        return null;
      }
      remotePort = remotePort2;
    }

    try {
      final String remoteAddressForVmParams;

      final boolean java9plus = Optional.ofNullable(request.getConfiguration())
        .map(TargetEnvironmentConfiguration::getRuntimes)
        .map(list -> list.findByType(JavaLanguageRuntimeConfiguration.class))
        .map(JavaLanguageRuntimeConfiguration::getJavaVersionString)
        .filter(StringUtil::isNotEmpty)
        .map(JavaSdkVersion::fromVersionString)
        .map(v -> v.isAtLeast(JavaSdkVersion.JDK_1_9))
        .orElse(false);

      if (java9plus) {
        // IDEA-225182 - hack: pass "host:port" to construct correct VM params, then adjust the connection
        // IDEA-265364 - enforce ipv4 here with explicit 0.0.0.0 address
        remoteAddressForVmParams = "0.0.0.0:" + remotePort;
      }
      else {
        remoteAddressForVmParams = String.valueOf(remotePort);
      }

      RemoteConnection remoteConnection = new RemoteConnectionBuilder(false, DebuggerSettings.SOCKET_TRANSPORT, remoteAddressForVmParams)
        .suspend(true)
        .create(javaParameters);

      remoteConnection.setApplicationAddress(String.valueOf(remotePort));
      if (java9plus) {
        remoteConnection.setApplicationHostName("*");
      }

      return new TargetDebuggerConnection(remoteConnection, new TargetEnvironment.TargetPortBinding(null, remotePort));
    }
    catch (ExecutionException e) {
      return null;
    }
  }
@Nullable
  public static TargetDebuggerConnection prepareDebuggerConnection(@NotNull JavaCommandLineState javaCommandLineState,
                                                                   @NotNull TargetEnvironmentRequest request)