code: private Set<InstalledExtension> getReplacedInstalledExtensions(Extension extension, String namespace)
          throws IncompatibleVersionConstraintException, ResolveException, InstallException
      {
          // If a namespace extension already exist on root, fail the install
          if (namespace != null) {
              checkRootExtension(extension.getId().getId());
          }
  
          Set<InstalledExtension> previousExtensions = new LinkedHashSet<>();
  
          Set<InstalledExtension> installedExtensions = getInstalledExtensions(extension.getId().getId(), namespace);
  
          VersionConstraint versionConstraint =
              checkReplacedInstalledExtensions(installedExtensions, extension.getId(), namespace, null);
          previousExtensions.addAll(installedExtensions);
  
          for (ExtensionId feature : extension.getExtensionFeatures()) {
              // If a namespace extension already exist on root, fail the install
              if (namespace != null) {
                  checkRootExtension(feature.getId());
              }
  
              installedExtensions = getInstalledExtensions(feature.getId(), namespace);
              versionConstraint =
                  checkReplacedInstalledExtensions(installedExtensions, feature, namespace, versionConstraint);
              previousExtensions.addAll(installedExtensions);
          }
  
          // If the extensions is already installed (usually mean we are trying to repair an invalid extension) it's not
          // going to replace itself
          if (extension instanceof InstalledExtension) {
              previousExtensions.remove(extension);
          }
  
          return previousExtensions;
      }
docs: Search and validate existing extensions that will be replaced by the extension.