Program: 47172
Project: 47172
Buggy source:
public void addChild(DLNAResource child,boolean isNew){
  if (child == null) {
    LOGGER.error("String_Node_Str",getName());
    LOGGER.debug("String_Node_Str",new NullPointerException("String_Node_Str"));
    return;
  }
  child.parent=this;
  child.masterParent=masterParent;
  if (parent != null) {
    defaultRenderer=parent.getDefaultRenderer();
  }
  if (PMS.filter(defaultRenderer,child)) {
    LOGGER.debug("String_Node_Str" + child.getName() + "String_Node_Str"+ defaultRenderer.getRendererName());
    return;
  }
  if (configuration.useCode() && !PMS.get().masterCodeValid()) {
    String code=PMS.get().codeDb().getCode(child);
    if (StringUtils.isNotEmpty(code)) {
      DLNAResource cobj=child.isCoded();
      if (cobj == null || !((CodeEnter)cobj).getCode().equals(code)) {
        LOGGER.debug("String_Node_Str" + child + "String_Node_Str");
        CodeEnter ce=new CodeEnter(child);
        ce.parent=this;
        ce.defaultRenderer=this.getDefaultRenderer();
        ce.setCode(code);
        addChildInternal(ce);
        return;
      }
    }
  }
  try {
    if (child.isValid()) {
      LOGGER.trace("String_Node_Str",isNew ? "String_Node_Str" : "String_Node_Str",child.getName(),child.getClass().getName());
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      child.resHash=Math.abs(child.getSystemName().hashCode() + resumeHash());
      DLNAResource resumeRes=null;
      boolean addResumeFile=false;
      ResumeObj r=ResumeObj.create(child);
      if (r != null) {
        resumeRes=child.clone();
        resumeRes.resume=r;
        resumeRes.resHash=child.resHash;
        addResumeFile=true;
      }
      if (child.format != null) {
        String configurationSkipExtensions=configuration.getDisableTranscodeForExtensions();
        String rendererSkipExtensions=null;
        if (defaultRenderer != null) {
          rendererSkipExtensions=defaultRenderer.getStreamedExtensions();
        }
        boolean skip=child.format.skip(configurationSkipExtensions,rendererSkipExtensions);
        skipTranscode=skip;
        if (skip) {
          LOGGER.trace("String_Node_Str",child.getName());
        }
        if (child.format.transcodable() || child.media != null) {
          if (child.media == null) {
            child.media=new DLNAMediaInfo();
          }
          Player player=null;
          String name=getName();
          if (!configuration.isHideRecentlyPlayedFolder()) {
            player=child.player;
          }
 else {
            for (            Player p : PlayerFactory.getPlayers()) {
              String end="String_Node_Str" + p.id() + "String_Node_Str";
              if (name.endsWith(end)) {
                nametruncate=name.lastIndexOf(end);
                player=p;
                LOGGER.trace("String_Node_Str");
                break;
              }
 else               if (parent != null && parent.getName().endsWith(end)) {
                parent.nametruncate=parent.getName().lastIndexOf(end);
                player=p;
                LOGGER.trace("String_Node_Str");
                break;
              }
            }
          }
          if (player == null || (hasExternalSubtitles() && defaultRenderer.isSubtitlesStreamingSupported())) {
            player=child.resolvePlayer(defaultRenderer);
          }
          boolean parserV2=child.media != null && defaultRenderer != null && defaultRenderer.isMediaParserV2();
          if (parserV2) {
            String mimeType=defaultRenderer.getFormatConfiguration().match(child.media);
            if (mimeType != null) {
              if (!FormatConfiguration.MIMETYPE_AUTO.equals(mimeType)) {
                child.media.setMimeType(mimeType);
              }
              LOGGER.trace("String_Node_Str",child.getName(),child.media.getMimeType());
            }
          }
          child.setPlayer(player);
          if (resumeRes != null) {
            resumeRes.player=player;
          }
          if (!allChildrenAreFolders) {
            child.setDefaultRenderer(defaultRenderer);
            if ((child.format.isVideo() || child.format.isAudio()) && child.isTranscodeFolderAvailable()) {
              VirtualFolder transcodeFolder=getTranscodeFolder(true);
              if (transcodeFolder != null) {
                VirtualFolder fileTranscodeFolder=new FileTranscodeVirtualFolder(child.getDisplayName(),null);
                DLNAResource newChild=child.clone();
                newChild.player=player;
                newChild.media=child.media;
                fileTranscodeFolder.addChildInternal(newChild);
                LOGGER.trace("String_Node_Str",child.getName(),player);
                transcodeFolder.updateChild(fileTranscodeFolder);
              }
            }
            if (child.format.isVideo() && child.isSubSelectable() && !(this instanceof SubSelFile)) {
              VirtualFolder vf=getSubSelector(true);
              if (vf != null) {
                DLNAResource newChild=child.clone();
                newChild.player=player;
                newChild.media=child.media;
                LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player);
                vf.addChild(new SubSelFile(newChild));
              }
            }
            if (configuration.isDynamicPls() && !child.isFolder() && defaultRenderer != null && !defaultRenderer.isNoDynPlsFolder()) {
              addDynamicPls(child);
            }
            for (            ExternalListener listener : ExternalFactory.getExternalListeners()) {
              if (listener instanceof AdditionalResourceFolderListener) {
                try {
                  ((AdditionalResourceFolderListener)listener).addAdditionalFolder(this,child);
                }
 catch (                Throwable t) {
                  LOGGER.error("String_Node_Str",listener.getClass(),t);
                }
              }
            }
          }
 else           if (!child.format.isCompatible(child.media,defaultRenderer) && !child.isFolder()) {
            LOGGER.trace("String_Node_Str",child.getName(),defaultRenderer.getRendererName());
            children.remove(child);
          }
        }
        if (resumeRes != null && resumeRes.media != null) {
          resumeRes.media.setThumbready(false);
        }
        if (child.format.getSecondaryFormat() != null && child.media != null && defaultRenderer != null && defaultRenderer.supportsFormat(child.format.getSecondaryFormat())) {
          DLNAResource newChild=child.clone();
          newChild.setFormat(newChild.format.getSecondaryFormat());
          LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          newChild.first=child;
          child.second=newChild;
          if (!newChild.format.isCompatible(newChild.media,defaultRenderer)) {
            Player player=PlayerFactory.getPlayer(newChild);
            newChild.setPlayer(player);
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getPlayer().name(),newChild.getName());
          }
          if (child.media != null && child.media.isSecondaryFormatValid()) {
            addChild(newChild);
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          }
 else {
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          }
        }
      }
      if (addResumeFile) {
        resumeRes.setDefaultRenderer(child.getDefaultRenderer());
        addChildInternal(resumeRes);
      }
      if (isNew) {
        addChildInternal(child);
      }
    }
  }
 catch (  Throwable t) {
    LOGGER.error("String_Node_Str",child.getName(),t);
    child.parent=null;
    children.remove(child);
  }
}

Fixed version (ground truth):
public void addChild(DLNAResource child,boolean isNew){
  if (child == null) {
    LOGGER.error("String_Node_Str",getName());
    LOGGER.debug("String_Node_Str",new NullPointerException("String_Node_Str"));
    return;
  }
  child.parent=this;
  child.masterParent=masterParent;
  if (parent != null) {
    defaultRenderer=parent.getDefaultRenderer();
  }
  if (PMS.filter(defaultRenderer,child)) {
    LOGGER.debug("String_Node_Str" + child.getName() + "String_Node_Str"+ defaultRenderer.getRendererName());
    return;
  }
  if (configuration.useCode() && !PMS.get().masterCodeValid()) {
    String code=PMS.get().codeDb().getCode(child);
    if (StringUtils.isNotEmpty(code)) {
      DLNAResource cobj=child.isCoded();
      if (cobj == null || !((CodeEnter)cobj).getCode().equals(code)) {
        LOGGER.debug("String_Node_Str" + child + "String_Node_Str");
        CodeEnter ce=new CodeEnter(child);
        ce.parent=this;
        ce.defaultRenderer=this.getDefaultRenderer();
        ce.setCode(code);
        addChildInternal(ce);
        return;
      }
    }
  }
  try {
    if (child.isValid()) {
      if ((child.format != null && defaultRenderer != null) && (child.format.isVideo() && !defaultRenderer.isVideoSupported() || child.format.isAudio() && !defaultRenderer.isAudioSupported() || child.format.isImage() && !defaultRenderer.isImageSupported())) {
        LOGGER.trace("String_Node_Str",child.getName(),defaultRenderer.getRendererName());
        children.remove(child);
        return;
      }
      LOGGER.trace("String_Node_Str",isNew ? "String_Node_Str" : "String_Node_Str",child.getName(),child.getClass().getName());
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      child.resHash=Math.abs(child.getSystemName().hashCode() + resumeHash());
      DLNAResource resumeRes=null;
      boolean addResumeFile=false;
      ResumeObj r=ResumeObj.create(child);
      if (r != null) {
        resumeRes=child.clone();
        resumeRes.resume=r;
        resumeRes.resHash=child.resHash;
        addResumeFile=true;
      }
      if (child.format != null) {
        String configurationSkipExtensions=configuration.getDisableTranscodeForExtensions();
        String rendererSkipExtensions=null;
        if (defaultRenderer != null) {
          rendererSkipExtensions=defaultRenderer.getStreamedExtensions();
        }
        boolean skip=child.format.skip(configurationSkipExtensions,rendererSkipExtensions);
        skipTranscode=skip;
        if (skip) {
          LOGGER.trace("String_Node_Str",child.getName());
        }
        if (child.format.transcodable() || child.media != null) {
          if (child.media == null) {
            child.media=new DLNAMediaInfo();
          }
          Player player=null;
          String name=getName();
          if (!configuration.isHideRecentlyPlayedFolder()) {
            player=child.player;
          }
 else {
            for (            Player p : PlayerFactory.getPlayers()) {
              String end="String_Node_Str" + p.id() + "String_Node_Str";
              if (name.endsWith(end)) {
                nametruncate=name.lastIndexOf(end);
                player=p;
                LOGGER.trace("String_Node_Str");
                break;
              }
 else               if (parent != null && parent.getName().endsWith(end)) {
                parent.nametruncate=parent.getName().lastIndexOf(end);
                player=p;
                LOGGER.trace("String_Node_Str");
                break;
              }
            }
          }
          if (player == null || (hasExternalSubtitles() && defaultRenderer.isSubtitlesStreamingSupported())) {
            player=child.resolvePlayer(defaultRenderer);
          }
          boolean parserV2=child.media != null && defaultRenderer != null && defaultRenderer.isMediaParserV2();
          if (parserV2) {
            String mimeType=defaultRenderer.getFormatConfiguration().match(child.media);
            if (mimeType != null) {
              if (!FormatConfiguration.MIMETYPE_AUTO.equals(mimeType)) {
                child.media.setMimeType(mimeType);
              }
              LOGGER.trace("String_Node_Str",child.getName(),child.media.getMimeType());
            }
          }
          child.setPlayer(player);
          if (resumeRes != null) {
            resumeRes.player=player;
          }
          if (!allChildrenAreFolders) {
            child.setDefaultRenderer(defaultRenderer);
            if ((child.format.isVideo() || child.format.isAudio()) && child.isTranscodeFolderAvailable()) {
              VirtualFolder transcodeFolder=getTranscodeFolder(true);
              if (transcodeFolder != null) {
                VirtualFolder fileTranscodeFolder=new FileTranscodeVirtualFolder(child.getDisplayName(),null);
                DLNAResource newChild=child.clone();
                newChild.player=player;
                newChild.media=child.media;
                fileTranscodeFolder.addChildInternal(newChild);
                LOGGER.trace("String_Node_Str",child.getName(),player);
                transcodeFolder.updateChild(fileTranscodeFolder);
              }
            }
            if (child.format.isVideo() && child.isSubSelectable() && !(this instanceof SubSelFile)) {
              VirtualFolder vf=getSubSelector(true);
              if (vf != null) {
                DLNAResource newChild=child.clone();
                newChild.player=player;
                newChild.media=child.media;
                LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player);
                vf.addChild(new SubSelFile(newChild));
              }
            }
            if (configuration.isDynamicPls() && !child.isFolder() && defaultRenderer != null && !defaultRenderer.isNoDynPlsFolder()) {
              addDynamicPls(child);
            }
            for (            ExternalListener listener : ExternalFactory.getExternalListeners()) {
              if (listener instanceof AdditionalResourceFolderListener) {
                try {
                  ((AdditionalResourceFolderListener)listener).addAdditionalFolder(this,child);
                }
 catch (                Throwable t) {
                  LOGGER.error("String_Node_Str",listener.getClass(),t);
                }
              }
            }
          }
 else           if (!child.format.isCompatible(child.media,defaultRenderer) && !child.isFolder()) {
            LOGGER.trace("String_Node_Str",child.getName(),defaultRenderer.getRendererName());
            children.remove(child);
          }
        }
        if (resumeRes != null && resumeRes.media != null) {
          resumeRes.media.setThumbready(false);
        }
        if (child.format.getSecondaryFormat() != null && child.media != null && defaultRenderer != null && defaultRenderer.supportsFormat(child.format.getSecondaryFormat())) {
          DLNAResource newChild=child.clone();
          newChild.setFormat(newChild.format.getSecondaryFormat());
          LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          newChild.first=child;
          child.second=newChild;
          if (!newChild.format.isCompatible(newChild.media,defaultRenderer)) {
            Player player=PlayerFactory.getPlayer(newChild);
            newChild.setPlayer(player);
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getPlayer().name(),newChild.getName());
          }
          if (child.media != null && child.media.isSecondaryFormatValid()) {
            addChild(newChild);
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          }
 else {
            LOGGER.trace("String_Node_Str",newChild.format.toString(),newChild.getName());
          }
        }
      }
      if (addResumeFile) {
        resumeRes.setDefaultRenderer(child.getDefaultRenderer());
        addChildInternal(resumeRes);
      }
      if (isNew) {
        addChildInternal(child);
      }
    }
  }
 catch (  Throwable t) {
    LOGGER.error("String_Node_Str",child.getName(),t);
    child.parent=null;
    children.remove(child);
  }
}