Program: 47269
Project: 47269
Buggy source:
/** 
 * Adds a new DLNAResource to the child list. Only useful if this object is of the container type.<P> TODO: (botijo) check what happens with the child object. This function can and will transform the child object. If the transcode option is set, the child item is converted to a container with the real item and the transcode option folder. There is also a parser in order to get the right name and type, I suppose. Is this the right place to be doing things like these?
 * @param child DLNAResource to add to a container type.
 */
public void addChild(DLNAResource child){
  if (child == null) {
    LOGGER.error("String_Node_Str" + getName());
    LOGGER.debug("String_Node_Str",new NullPointerException("String_Node_Str"));
    return;
  }
  child.setParent(this);
  if (getParent() != null) {
    setDefaultRenderer(getParent().getDefaultRenderer());
  }
  try {
    if (child.isValid()) {
      LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ child.getClass().getName());
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      child.resHash=Math.abs(child.getSystemName().hashCode() + resumeHash());
      DLNAResource resumeRes=null;
      ResumeObj r=ResumeObj.create(child);
      if (r != null) {
        resumeRes=child.clone();
        resumeRes.resume=r;
        resumeRes.resHash=child.resHash;
        addChildInternal(resumeRes);
      }
      addChildInternal(child);
      boolean forceTranscodeV2=false;
      boolean parserV2=child.getMedia() != null && getDefaultRenderer() != null && getDefaultRenderer().isMediaParserV2();
      if (parserV2) {
        String mimeType=getDefaultRenderer().getFormatConfiguration().match(child.getMedia());
        if (mimeType != null) {
          child.getMedia().setMimeType(mimeType.equals(FormatConfiguration.MIMETYPE_AUTO) ? child.getMedia().getMimeType() : mimeType);
        }
 else {
          forceTranscodeV2=true;
        }
      }
      if (child.getFormat() != null) {
        setSkipTranscode(child.getFormat().skip(configuration.getNoTranscode(),getDefaultRenderer() != null ? getDefaultRenderer().getStreamedExtensions() : null));
      }
      if (child.getFormat() != null && (child.getFormat().transcodable() || parserV2) && (child.getMedia() == null || parserV2)) {
        if (!parserV2) {
          child.setMedia(new DLNAMediaInfo());
        }
        Player player=null;
        String name=getName();
        for (        Player p : PlayerFactory.getAllPlayers()) {
          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 (getParent() != null && getParent().getName().endsWith(end)) {
            getParent().nametruncate=getParent().getName().lastIndexOf(end);
            player=p;
            LOGGER.trace("String_Node_Str");
            break;
          }
        }
        if (player == null) {
          player=PlayerFactory.getPlayer(child);
        }
        if (player != null && !allChildrenAreFolders) {
          boolean forceTranscode=false;
          if (child.getFormat() != null) {
            forceTranscode=child.getFormat().skip(configuration.getForceTranscode(),getDefaultRenderer() != null ? getDefaultRenderer().getTranscodedExtensions() : null);
          }
          boolean hasEmbeddedSubs=false;
          if (child.getMedia() != null) {
            for (            DLNAMediaSubtitle s : child.getMedia().getSubtitleTracksList()) {
              hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
            }
          }
          boolean hasSubsToTranscode=false;
          if (!configuration.isDisableSubtitles()) {
            hasSubsToTranscode=(configuration.isAutoloadSubtitles() && child.isSrtFile()) || hasEmbeddedSubs || liveSubs(child);
          }
          boolean isIncompatible=false;
          if (!child.getFormat().isCompatible(child.getMedia(),getDefaultRenderer())) {
            isIncompatible=true;
          }
          if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
            child.setPlayer(player);
            if (resumeRes != null) {
              DLNAMediaInfo mi=child.getMedia();
              if (mi != null) {
                mi=(DLNAMediaInfo)mi.clone();
                resumeRes.setMedia(mi);
              }
              resumeRes.setPlayer(player);
            }
            LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString()+ "String_Node_Str");
          }
          if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
            VirtualFolder transcodeFolder=getTranscodeFolder(true);
            if (transcodeFolder != null) {
              VirtualFolder fileTranscodeFolder=new FileTranscodeVirtualFolder(child.getDisplayName(),null);
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              fileTranscodeFolder.addChildInternal(newChild);
              LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
              transcodeFolder.addChild(fileTranscodeFolder);
            }
          }
          if (child.getExt().isVideo() && child.isSubSelectable()) {
            VirtualFolder vf=getSubSelector(true);
            if (vf != null) {
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              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.getFormat().isCompatible(child.getMedia(),getDefaultRenderer()) && !child.isFolder()) {
          getChildren().remove(child);
        }
      }
      if (child.getFormat() != null && child.getFormat().getSecondaryFormat() != null && child.getMedia() != null && getDefaultRenderer() != null && getDefaultRenderer().supportsFormat(child.getFormat().getSecondaryFormat())) {
        DLNAResource newChild=child.clone();
        newChild.setFormat(newChild.getFormat().getSecondaryFormat());
        newChild.first=child;
        child.second=newChild;
        if (!newChild.getFormat().isCompatible(newChild.getMedia(),getDefaultRenderer())) {
          Player player=PlayerFactory.getPlayer(newChild);
          newChild.setPlayer(player);
        }
        if (child.getMedia() != null && child.getMedia().isSecondaryFormatValid()) {
          addChild(newChild);
        }
      }
    }
  }
 catch (  Throwable t) {
    LOGGER.error("String_Node_Str",child.getName(),t);
    child.setParent(null);
    getChildren().remove(child);
  }
}

Fixed version (ground truth):
/** 
 * Adds a new DLNAResource to the child list. Only useful if this object is of the container type.<P> TODO: (botijo) check what happens with the child object. This function can and will transform the child object. If the transcode option is set, the child item is converted to a container with the real item and the transcode option folder. There is also a parser in order to get the right name and type, I suppose. Is this the right place to be doing things like these?
 * @param child DLNAResource to add to a container type.
 */
public void addChild(DLNAResource child){
  if (child == null) {
    LOGGER.error("String_Node_Str" + getName());
    LOGGER.debug("String_Node_Str",new NullPointerException("String_Node_Str"));
    return;
  }
  child.setParent(this);
  if (getParent() != null) {
    setDefaultRenderer(getParent().getDefaultRenderer());
  }
  try {
    if (child.isValid()) {
      LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ child.getClass().getName());
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      child.resHash=Math.abs(child.getSystemName().hashCode() + resumeHash());
      DLNAResource resumeRes=null;
      ResumeObj r=ResumeObj.create(child);
      if (r != null) {
        resumeRes=child.clone();
        resumeRes.resume=r;
        resumeRes.resHash=child.resHash;
        addChildInternal(resumeRes);
      }
      addChildInternal(child);
      boolean forceTranscodeV2=false;
      boolean parserV2=child.getMedia() != null && getDefaultRenderer() != null && getDefaultRenderer().isMediaParserV2();
      if (parserV2) {
        String mimeType=getDefaultRenderer().getFormatConfiguration().match(child.getMedia());
        if (mimeType != null) {
          child.getMedia().setMimeType(mimeType.equals(FormatConfiguration.MIMETYPE_AUTO) ? child.getMedia().getMimeType() : mimeType);
        }
 else {
          forceTranscodeV2=true;
        }
      }
      if (child.getFormat() != null) {
        setSkipTranscode(child.getFormat().skip(configuration.getNoTranscode(),getDefaultRenderer() != null ? getDefaultRenderer().getStreamedExtensions() : null));
      }
      if (child.getFormat() != null && (child.getFormat().transcodable() || parserV2) && (child.getMedia() == null || parserV2)) {
        if (!parserV2) {
          child.setMedia(new DLNAMediaInfo());
        }
        Player player=null;
        String name=getName();
        for (        Player p : PlayerFactory.getAllPlayers()) {
          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 (getParent() != null && getParent().getName().endsWith(end)) {
            getParent().nametruncate=getParent().getName().lastIndexOf(end);
            player=p;
            LOGGER.trace("String_Node_Str");
            break;
          }
        }
        if (player == null) {
          player=PlayerFactory.getPlayer(child);
        }
        if (player != null && !allChildrenAreFolders) {
          boolean forceTranscode=false;
          if (child.getFormat() != null) {
            forceTranscode=child.getFormat().skip(configuration.getForceTranscode(),getDefaultRenderer() != null ? getDefaultRenderer().getTranscodedExtensions() : null);
          }
          boolean hasEmbeddedSubs=false;
          if (child.getMedia() != null) {
            for (            DLNAMediaSubtitle s : child.getMedia().getSubtitleTracksList()) {
              hasEmbeddedSubs=(hasEmbeddedSubs || s.isEmbedded());
            }
          }
          boolean hasSubsToTranscode=false;
          if (!configuration.isDisableSubtitles()) {
            hasSubsToTranscode=(configuration.isAutoloadSubtitles() && child.isSrtFile()) || hasEmbeddedSubs || liveSubs(child);
          }
          boolean isIncompatible=false;
          if (!child.getFormat().isCompatible(child.getMedia(),getDefaultRenderer())) {
            isIncompatible=true;
          }
          if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
            child.setPlayer(player);
            if (resumeRes != null) {
              resumeRes.setPlayer(player);
            }
            LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString()+ "String_Node_Str");
          }
          if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
            VirtualFolder transcodeFolder=getTranscodeFolder(true);
            if (transcodeFolder != null) {
              VirtualFolder fileTranscodeFolder=new FileTranscodeVirtualFolder(child.getDisplayName(),null);
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              fileTranscodeFolder.addChildInternal(newChild);
              LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
              transcodeFolder.addChild(fileTranscodeFolder);
            }
          }
          if (child.getExt().isVideo() && child.isSubSelectable()) {
            VirtualFolder vf=getSubSelector(true);
            if (vf != null) {
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              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.getFormat().isCompatible(child.getMedia(),getDefaultRenderer()) && !child.isFolder()) {
          getChildren().remove(child);
        }
      }
      if (resumeRes != null) {
        resumeRes.setMedia(child.getMedia());
      }
      if (child.getFormat() != null && child.getFormat().getSecondaryFormat() != null && child.getMedia() != null && getDefaultRenderer() != null && getDefaultRenderer().supportsFormat(child.getFormat().getSecondaryFormat())) {
        DLNAResource newChild=child.clone();
        newChild.setFormat(newChild.getFormat().getSecondaryFormat());
        newChild.first=child;
        child.second=newChild;
        if (!newChild.getFormat().isCompatible(newChild.getMedia(),getDefaultRenderer())) {
          Player player=PlayerFactory.getPlayer(newChild);
          newChild.setPlayer(player);
        }
        if (child.getMedia() != null && child.getMedia().isSecondaryFormatValid()) {
          addChild(newChild);
        }
      }
    }
  }
 catch (  Throwable t) {
    LOGGER.error("String_Node_Str",child.getName(),t);
    child.setParent(null);
    getChildren().remove(child);
  }
}