Program: 32893
Project: 32893
Buggy source:
@NotNull private static Module createAndSetupModule(String moduleName,@NotNull Project project,@NotNull ModifiableModuleModel modifiableModuleModels,@NotNull String[] paths,@Nullable Sdk unitySdk,@NotNull Consumer<ModuleRootLayerImpl> setupConsumer,@NotNull String moduleExtensionId,@NotNull final FileType fileType,@NotNull final MultiMap<Module,VirtualFile> virtualFilesByModule){
  for (int i=0; i < paths.length; i++) {
    paths[i]=project.getBasePath() + "String_Node_Str" + paths[i];
  }
  Module temp=modifiableModuleModels.findModuleByName(moduleName);
  final Module module;
  if (temp == null) {
    module=modifiableModuleModels.newModule(moduleName,null);
  }
 else {
    module=temp;
  }
  ModuleRootManager moduleRootManager=ModuleRootManager.getInstance(module);
  val modifiableModel=moduleRootManager.getModifiableModel();
  modifiableModel.removeAllLayers(false);
  for (  Unity3dTarget unity3dTarget : Unity3dTarget.values()) {
    val layer=(ModuleRootLayerImpl)modifiableModel.addLayer(unity3dTarget.getPresentation(),null,getDefaultTarget() == unity3dTarget);
    for (    String path : paths) {
      VirtualFile fileByPath=LocalFileSystem.getInstance().findFileByPath(path);
      if (fileByPath != null) {
        VfsUtil.visitChildrenRecursively(fileByPath,new VirtualFileVisitor(){
          @Override public boolean visitFile(          @NotNull VirtualFile file){
            if (file.getFileType() == fileType) {
              if (virtualFilesByModule.containsScalarValue(file)) {
                return true;
              }
              virtualFilesByModule.putValue(module,file);
              layer.addContentEntry(file);
            }
            return true;
          }
        }
);
      }
    }
    setupConsumer.consume(layer);
    layer.getExtensionWithoutCheck(Unity3dChildMutableModuleExtension.class).setEnabled(true);
    layer.<MutableModuleExtension>getExtensionWithoutCheck(moduleExtensionId).setEnabled(true);
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    if (isVersionHigherOrEqual(unitySdk,"String_Node_Str")) {
      layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    }
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
  }
  new WriteAction<Object>(){
    @Override protected void run(    Result<Object> result) throws Throwable {
      modifiableModel.commit();
    }
  }
.execute();
  return module;
}

Fixed version (ground truth):
@NotNull private static Module createAndSetupModule(String moduleName,@NotNull Project project,@NotNull ModifiableModuleModel modifiableModuleModels,@NotNull String[] paths,@Nullable Sdk unitySdk,@NotNull Consumer<ModuleRootLayerImpl> setupConsumer,@NotNull String moduleExtensionId,@NotNull final FileType fileType,@NotNull final MultiMap<Module,VirtualFile> virtualFilesByModule){
  for (int i=0; i < paths.length; i++) {
    paths[i]=project.getBasePath() + "String_Node_Str" + paths[i];
  }
  Module temp=modifiableModuleModels.findModuleByName(moduleName);
  final Module module;
  if (temp == null) {
    module=modifiableModuleModels.newModule(moduleName,null);
  }
 else {
    module=temp;
  }
  ModuleRootManager moduleRootManager=ModuleRootManager.getInstance(module);
  val modifiableModel=moduleRootManager.getModifiableModel();
  modifiableModel.removeAllLayers(false);
  final List<VirtualFile> toAdd=new ArrayList<VirtualFile>();
  for (  String path : paths) {
    VirtualFile fileByPath=LocalFileSystem.getInstance().findFileByPath(path);
    if (fileByPath != null) {
      VfsUtil.visitChildrenRecursively(fileByPath,new VirtualFileVisitor(){
        @Override public boolean visitFile(        @NotNull VirtualFile file){
          if (file.getFileType() == fileType) {
            if (virtualFilesByModule.containsScalarValue(file)) {
              return true;
            }
            virtualFilesByModule.putValue(module,file);
            toAdd.add(file);
          }
          return true;
        }
      }
);
    }
  }
  for (  final Unity3dTarget unity3dTarget : Unity3dTarget.values()) {
    val layer=(ModuleRootLayerImpl)modifiableModel.addLayer(unity3dTarget.getPresentation(),null,getDefaultTarget() == unity3dTarget);
    for (    VirtualFile virtualFile : toAdd) {
      layer.addContentEntry(virtualFile);
    }
    setupConsumer.consume(layer);
    layer.getExtensionWithoutCheck(Unity3dChildMutableModuleExtension.class).setEnabled(true);
    layer.<MutableModuleExtension>getExtensionWithoutCheck(moduleExtensionId).setEnabled(true);
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    if (isVersionHigherOrEqual(unitySdk,"String_Node_Str")) {
      layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    }
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
    layer.addOrderEntry(new DotNetLibraryOrderEntryImpl(layer,"String_Node_Str"));
  }
  new WriteAction<Object>(){
    @Override protected void run(    Result<Object> result) throws Throwable {
      modifiableModel.commit();
    }
  }
.execute();
  return module;
}