private synchronized void insertKeyManager(
      final KeyManager<?> manager, boolean forceOverwrite, boolean newKeyAllowed)
      throws GeneralSecurityException {
    String typeUrl = manager.getKeyType();
    if (newKeyAllowed && newKeyAllowedMap.containsKey(typeUrl) && !newKeyAllowedMap.get(typeUrl)) {
      throw new GeneralSecurityException("New keys are already disallowed for key type " + typeUrl);
    }
    KeyManager<?> existing = keyManagerMap.get(typeUrl);
    if (existing != null && !existing.getClass().equals(manager.getClass())) {
      logger.warning("Attempted overwrite of a registered key manager for key type " + typeUrl);
      throw new GeneralSecurityException(
          String.format(
              "typeUrl (%s) is already registered with %s, cannot be re-registered with %s",
              typeUrl, existing.getClass().getName(), manager.getClass().getName()));
    }
    if (!forceOverwrite) {
      keyManagerMap.putIfAbsent(typeUrl, manager);
    } else {
      keyManagerMap.put(typeUrl, manager);
    }
    newKeyAllowedMap.put(typeUrl, newKeyAllowed);
  }
Resets the global instance. Should only be used in tests. Not thread safe.
java_src/src/main/java/com/google/crypto/tink/internal/KeyManagerRegistry.java