Program: 47227
Project: 47227
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;
  }
  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;
      }
      boolean parserV2=child.media != null && defaultRenderer != null && defaultRenderer.isMediaParserV2();
      if (parserV2) {
        String mimeType=defaultRenderer.getFormatConfiguration().match(child.media);
        if (mimeType != null) {
          if (!configuration.isDisableSubtitles() && child.isSubsFile() && defaultRenderer.isSubtitlesStreamingSupported()) {
            OutputParams params=new OutputParams(configuration);
            Player.setAudioAndSubs(child.getSystemName(),child.media,params);
            if (defaultRenderer.isSubtitlesFormatSupported(params.sid)) {
              child.media_subtitle=params.sid;
              LOGGER.trace("String_Node_Str");
            }
 else {
              LOGGER.trace("String_Node_Str");
            }
          }
 else {
            LOGGER.trace("String_Node_Str");
          }
          if (!FormatConfiguration.MIMETYPE_AUTO.equals(mimeType)) {
            LOGGER.trace("String_Node_Str",child.media.getMimeType(),child.getName(),mimeType);
            child.media.setMimeType(mimeType);
          }
          LOGGER.trace("String_Node_Str",child.getName(),child.media.getMimeType());
        }
 else {
          LOGGER.trace("String_Node_Str",child.getName());
        }
      }
 else       if (child.media != null) {
        LOGGER.trace("String_Node_Str",child.getName(),defaultRenderer);
      }
      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) {
            player=PlayerFactory.getPlayer(child);
          }
          if (player != null && !allChildrenAreFolders) {
            String configurationForceExtensions=configuration.getForceTranscodeForExtensions();
            String rendererForceExtensions=null;
            if (defaultRenderer != null) {
              rendererForceExtensions=defaultRenderer.getTranscodedExtensions();
            }
            boolean forceTranscode=child.format.skip(configurationForceExtensions,rendererForceExtensions);
            if (forceTranscode) {
              LOGGER.trace("String_Node_Str",child.getName());
            }
            boolean hasEmbeddedSubs=false;
            if (child.media != null) {
              for (              DLNAMediaSubtitle s : child.media.getSubtitleTracksList()) {
                hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
              }
              if (!parserV2) {
                if (!configuration.isDisableSubtitles() && child.isSubsFile() && defaultRenderer.isSubtitlesStreamingSupported()) {
                  OutputParams params=new OutputParams(configuration);
                  Player.setAudioAndSubs(child.getSystemName(),child.media,params);
                  if (defaultRenderer.isSubtitlesFormatSupported(params.sid)) {
                    child.media_subtitle=params.sid;
                    LOGGER.trace("String_Node_Str");
                  }
 else {
                    LOGGER.trace("String_Node_Str");
                  }
                }
 else {
                  LOGGER.trace("String_Node_Str");
                }
              }
            }
            boolean hasSubsToTranscode=false;
            if (!configuration.isDisableSubtitles()) {
              if (child.isSubsFile()) {
                if (child.media_subtitle == null) {
                  hasSubsToTranscode=true;
                  LOGGER.trace("String_Node_Str",child.getName());
                }
 else {
                  LOGGER.trace("String_Node_Str",child.getName());
                }
                hasSubsToTranscode=(child.media_subtitle == null);
              }
 else {
                if (hasEmbeddedSubs && defaultRenderer != null && !defaultRenderer.isEmbeddedSubtitlesSupported()) {
                  hasSubsToTranscode=true;
                  LOGGER.trace("String_Node_Str",child.getName());
                }
 else {
                  LOGGER.trace("String_Node_Str",child.getName());
                }
              }
            }
            boolean isIncompatible=false;
            String audioTracksList=child.getName() + child.media.getAudioTracksList().toString();
            if (!child.format.isCompatible(child.media,defaultRenderer)) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
 else             if (configuration.isEncodedAudioPassthrough() && (audioTracksList.contains("String_Node_Str") || audioTracksList.contains("String_Node_Str"))) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
 else             if (defaultRenderer != null && defaultRenderer.isKeepAspectRatio() && !"String_Node_Str".equals(child.media.getAspectRatioContainer())) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName(),child.media.getAspectRatioContainer());
            }
 else             if (defaultRenderer != null && defaultRenderer.isMaximumResolutionSpecified() && (child.media.getWidth() > defaultRenderer.getMaxVideoWidth() || child.media.getHeight() > defaultRenderer.getMaxVideoHeight())) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
            boolean preferTranscode=isIncompatible || hasSubsToTranscode;
            if (forceTranscode || (preferTranscode && !isSkipTranscode())) {
              child.player=player;
              if (resumeRes != null) {
                resumeRes.player=player;
              }
              if (parserV2) {
                LOGGER.trace("String_Node_Str",child.getName(),player.toString(),child.media.getMimeType());
              }
 else {
                LOGGER.trace("String_Node_Str",child.getName(),player.toString());
              }
            }
 else {
              LOGGER.trace("String_Node_Str",child.getName());
            }
            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.toString());
                transcodeFolder.updateChild(fileTranscodeFolder);
              }
            }
            if (child.format.isVideo() && child.isSubSelectable() && !(this instanceof SubSelFile)) {
              VirtualFolder vf=getSubSelector(true);
              if (vf != null) {
                DLNAResource newChild=child.clone();
                newChild.setPlayer(player);
                newChild.setMedia(child.media);
                LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
                vf.addChild(new SubSelFile(newChild));
              }
            }
            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) {
        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;
  }
  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;
      }
      boolean parserV2=child.media != null && defaultRenderer != null && defaultRenderer.isMediaParserV2();
      if (parserV2) {
        String mimeType=defaultRenderer.getFormatConfiguration().match(child.media);
        if (mimeType != null) {
          if (!configuration.isDisableSubtitles() && child.isSubsFile() && defaultRenderer.isSubtitlesStreamingSupported()) {
            OutputParams params=new OutputParams(configuration);
            Player.setAudioAndSubs(child.getSystemName(),child.media,params);
            if (defaultRenderer.isSubtitlesFormatSupported(params.sid)) {
              child.media_subtitle=params.sid;
              LOGGER.trace("String_Node_Str");
            }
 else {
              LOGGER.trace("String_Node_Str");
            }
          }
 else {
            LOGGER.trace("String_Node_Str");
          }
          if (!FormatConfiguration.MIMETYPE_AUTO.equals(mimeType)) {
            LOGGER.trace("String_Node_Str",child.media.getMimeType(),child.getName(),mimeType);
            child.media.setMimeType(mimeType);
          }
          LOGGER.trace("String_Node_Str",child.getName(),child.media.getMimeType());
        }
 else {
          LOGGER.trace("String_Node_Str",child.getName());
        }
      }
 else       if (child.media != null) {
        LOGGER.trace("String_Node_Str",child.getName(),defaultRenderer);
      }
      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) {
            player=PlayerFactory.getPlayer(child);
          }
          if (player != null && !allChildrenAreFolders) {
            String configurationForceExtensions=configuration.getForceTranscodeForExtensions();
            String rendererForceExtensions=null;
            if (defaultRenderer != null) {
              rendererForceExtensions=defaultRenderer.getTranscodedExtensions();
            }
            boolean forceTranscode=child.format.skip(configurationForceExtensions,rendererForceExtensions);
            if (forceTranscode) {
              LOGGER.trace("String_Node_Str",child.getName());
            }
            boolean hasEmbeddedSubs=false;
            if (child.media != null) {
              for (              DLNAMediaSubtitle s : child.media.getSubtitleTracksList()) {
                hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
              }
              if (!parserV2) {
                if (!configuration.isDisableSubtitles() && child.isSubsFile() && defaultRenderer.isSubtitlesStreamingSupported()) {
                  OutputParams params=new OutputParams(configuration);
                  Player.setAudioAndSubs(child.getSystemName(),child.media,params);
                  if (defaultRenderer.isSubtitlesFormatSupported(params.sid)) {
                    child.media_subtitle=params.sid;
                    LOGGER.trace("String_Node_Str");
                  }
 else {
                    LOGGER.trace("String_Node_Str");
                  }
                }
 else {
                  LOGGER.trace("String_Node_Str");
                }
              }
            }
            boolean hasSubsToTranscode=false;
            if (!configuration.isDisableSubtitles()) {
              if (child.isSubsFile()) {
                if (child.media_subtitle == null) {
                  forceTranscode=true;
                  hasSubsToTranscode=true;
                  LOGGER.trace("String_Node_Str",child.getName());
                }
 else {
                  LOGGER.trace("String_Node_Str",child.getName());
                }
              }
 else {
                if (hasEmbeddedSubs && defaultRenderer != null && !defaultRenderer.isEmbeddedSubtitlesSupported()) {
                  forceTranscode=true;
                  hasSubsToTranscode=true;
                  LOGGER.trace("String_Node_Str",child.getName());
                }
 else {
                  LOGGER.trace("String_Node_Str",child.getName());
                }
              }
            }
            boolean isIncompatible=false;
            String audioTracksList=child.getName() + child.media.getAudioTracksList().toString();
            if (!child.format.isCompatible(child.media,defaultRenderer)) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
 else             if (configuration.isEncodedAudioPassthrough() && (audioTracksList.contains("String_Node_Str") || audioTracksList.contains("String_Node_Str"))) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
 else             if (defaultRenderer != null && defaultRenderer.isKeepAspectRatio() && !"String_Node_Str".equals(child.media.getAspectRatioContainer())) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName(),child.media.getAspectRatioContainer());
            }
 else             if (defaultRenderer != null && defaultRenderer.isMaximumResolutionSpecified() && (child.media.getWidth() > defaultRenderer.getMaxVideoWidth() || child.media.getHeight() > defaultRenderer.getMaxVideoHeight())) {
              isIncompatible=true;
              LOGGER.trace("String_Node_Str",child.getName());
            }
            boolean preferTranscode=isIncompatible || hasSubsToTranscode;
            if (forceTranscode || (preferTranscode && !isSkipTranscode())) {
              child.player=player;
              if (resumeRes != null) {
                resumeRes.player=player;
              }
              if (parserV2) {
                LOGGER.trace("String_Node_Str",child.getName(),player.toString(),child.media.getMimeType());
              }
 else {
                LOGGER.trace("String_Node_Str",child.getName(),player.toString());
              }
            }
 else {
              LOGGER.trace("String_Node_Str",child.getName());
            }
            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.toString());
                transcodeFolder.updateChild(fileTranscodeFolder);
              }
            }
            if (child.format.isVideo() && child.isSubSelectable() && !(this instanceof SubSelFile)) {
              VirtualFolder vf=getSubSelector(true);
              if (vf != null) {
                DLNAResource newChild=child.clone();
                newChild.setPlayer(player);
                newChild.setMedia(child.media);
                LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
                vf.addChild(new SubSelFile(newChild));
              }
            }
            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) {
        addChildInternal(resumeRes);
      }
      if (isNew) {
        addChildInternal(child);
      }
    }
  }
 catch (  Throwable t) {
    LOGGER.error("String_Node_Str",child.getName(),t);
    child.parent=null;
    children.remove(child);
  }
}