private void lockDirectory(Path lockFile) throws IOException, IllegalStateException {
    IOException first = null;

    for (var i = 0; i < LOCK_RETRIES; i++) {
      try {
        Files.writeString(lockFile, myPid, StandardOpenOption.CREATE_NEW);
        return;
      }
      catch (FileAlreadyExistsException e) {
        first = Suppressions.addSuppressed(first, e);
        try {
          try {
            var otherPid = Long.parseLong(Files.readString(lockFile));
            var handle = ProcessHandle.of(otherPid).orElse(null);
            if (handle != null) {
              var command = Path.of(handle.info().command().orElse(""));
              if (command.endsWith(SystemInfoRt.isWindows ? "java.exe" : "java") ||
                  command.endsWith(ApplicationNamesInfo.getInstance().getScriptName() + (SystemInfoRt.isWindows ? "64.exe" : ""))) {
                throw new IllegalStateException(BootstrapBundle.message("bootstrap.error.still.running", command, Long.toString(otherPid), lockFile), e);
              }
            }
          }
          catch (NumberFormatException | InvalidPathException ignored) { }
          Files.deleteIfExists(lockFile);
        }
        catch (IOException ex) {
          first = Suppressions.addSuppressed(first, ex);
        }
      }
    }

    throw first;
  }
private void lockDirectory(Path lockFile)