private @Nullable FileTypeWithDescriptor instantiateFileTypeBean(@NotNull FileTypeBean bean) {
    Lock writeLock = myPendingInitializationLock.writeLock();
    writeLock.lock();
    try {
      String fileTypeName = bean.name;
      // DCL
      StandardFileType type = standardFileTypes.get(fileTypeName);
      if (type != null) {
        type.matchers.addAll(bean.getMatchers());
        for (FileNameMatcher matcher : bean.getMatchers()) {
          patternsTable.addAssociation(matcher, type.getDescriptor());
        }
        return type.getDescriptor();
      }

      if (!pendingFileTypes.containsKey(fileTypeName)) {
        FileTypeWithDescriptor ftd = schemeManager.findSchemeByName(fileTypeName);
        if (ftd != null && !(ftd.fileType() instanceof AbstractFileType)) {
          return ftd;
        }
      }

      PluginId pluginId = bean.getPluginDescriptor().getPluginId();
      FileType fileType = null;
      try {
        Class<Object> aClass = ApplicationManager.getApplication().loadClass(bean.implementationClass, bean.getPluginDescriptor());
        Field field = getField(bean, aClass);
        if (field != null) {
          field.setAccessible(true);
          fileType = (FileType)field.get(null);
        }
        if (fileType == null) {
          if (INSTANTIATED != null && !INSTANTIATED.add(fileTypeName)) {
            throw new IllegalStateException("File type '" + fileTypeName + "' instantiated twice. Descriptor=" + bean.getPluginDescriptor() + "; fieldName=" + bean.fieldName + "." +
                                            " Maybe adding this to the class '" + bean.implementationClass + "' will help: `private static final " +
                                            bean.implementationClass + " INSTANCE = new " + bean.implementationClass + "()`");
          }
          fileType = ApplicationManager.getApplication().instantiateClass(bean.implementationClass, bean.getPluginDescriptor());
        }
      }
      catch (CancellationException e) {
        throw e;
      }
      catch (Exception e) {
        // no need to wrap into PluginException - instantiateClass and loadClass both do this if needed
        LOG.error(e);
        return null;
      }

      if (!fileType.getName().equals(fileTypeName)) {
        LOG.error(new PluginException("Incorrect name specified in <fileType>, should be " + fileType.getName() + ", actual " + fileTypeName, pluginId));
      }
      if (fileType instanceof LanguageFileType languageFileType) {
        String expectedLanguage = languageFileType.isSecondary() ? null : languageFileType.getLanguage().getID();
        if (!Objects.equals(bean.language, expectedLanguage)) {
          LOG.error(new PluginException("Incorrect language specified in <fileType> for " + fileType.getName() +
                                        ", should be " + expectedLanguage + ", actual " + bean.language, pluginId));
        }
      }

      StandardFileType standardFileType = new StandardFileType(fileType, bean.getPluginDescriptor(), bean.getMatchers());
      standardFileTypes.put(bean.name, standardFileType);
      PluginAdvertiserExtensionsStateService pluginAdvertiserExtensionsStateService =
        PluginAdvertiserExtensionsStateService.Companion.getInstance();
      registerFileTypeWithoutNotification(fileType,
                                          bean.getPluginDescriptor(),
                                          standardFileType.matchers,
                                          pluginAdvertiserExtensionsStateService,
                                          true);

      if (bean.hashBangs != null) {
        for (String hashBang : StringUtil.split(bean.hashBangs, ";")) {
          patternsTable.addHashBangPattern(hashBang, new FileTypeWithDescriptor(fileType, bean.getPluginDescriptor()));
          initialAssociations.addHashBangPattern(hashBang, fileType);
        }
      }

      pendingAssociations.removeAllAssociations(bean);
      pendingFileTypes.remove(fileTypeName);

      return new FileTypeWithDescriptor(fileType, bean.getPluginDescriptor());
    }
    finally {
      writeLock.unlock();
    }
  }
private @Nullable FileTypeWithDescriptor instantiateFileTypeBean(@NotNull FileTypeBean bean)