Program: 47293
Project: 47293
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(),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());
      VirtualFolder vf;
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      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(PMS.getConfiguration().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.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 (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(PMS.getConfiguration().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 (!PMS.getConfiguration().isMencoderDisableSubs()) {
            hasSubsToTranscode=(PMS.getConfiguration().isAutoloadSubtitles() && child.isSrtFile()) || hasEmbeddedSubs;
          }
          boolean isIncompatible=false;
          if (!child.getFormat().isCompatible(child.getMedia(),getDefaultRenderer())) {
            isIncompatible=true;
          }
          if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
            child.setPlayer(player);
            LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString()+ "String_Node_Str");
          }
          if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
            vf=getTranscodeFolder(true);
            if (vf != null) {
              VirtualFolder fileFolder=new FileTranscodeVirtualFolder(child.getName(),null);
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              fileFolder.addChildInternal(newChild);
              LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
              vf.addChild(fileFolder);
            }
          }
          for (          ExternalListener listener : ExternalFactory.getExternalListeners()) {
            if (listener instanceof AdditionalResourceFolderListener) {
              try {
                ((AdditionalResourceFolderListener)listener).addAdditionalFolder(this,child);
              }
 catch (              Throwable t) {
                LOGGER.error(String.format("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.format("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(),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());
      VirtualFolder vf;
      if (allChildrenAreFolders && !child.isFolder()) {
        allChildrenAreFolders=false;
      }
      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(PMS.getConfiguration().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(PMS.getConfiguration().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 (!PMS.getConfiguration().isMencoderDisableSubs()) {
            hasSubsToTranscode=(PMS.getConfiguration().isAutoloadSubtitles() && child.isSrtFile()) || hasEmbeddedSubs;
          }
          boolean isIncompatible=false;
          if (!child.getFormat().isCompatible(child.getMedia(),getDefaultRenderer())) {
            isIncompatible=true;
          }
          if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
            child.setPlayer(player);
            LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString()+ "String_Node_Str");
          }
          if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
            vf=getTranscodeFolder(true);
            if (vf != null) {
              VirtualFolder fileFolder=new FileTranscodeVirtualFolder(child.getName(),null);
              DLNAResource newChild=child.clone();
              newChild.setPlayer(player);
              newChild.setMedia(child.getMedia());
              fileFolder.addChildInternal(newChild);
              LOGGER.trace("String_Node_Str" + child.getName() + "String_Node_Str"+ player.toString());
              vf.addChild(fileFolder);
            }
          }
          for (          ExternalListener listener : ExternalFactory.getExternalListeners()) {
            if (listener instanceof AdditionalResourceFolderListener) {
              try {
                ((AdditionalResourceFolderListener)listener).addAdditionalFolder(this,child);
              }
 catch (              Throwable t) {
                LOGGER.error(String.format("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.format("String_Node_Str",child.getName()),t);
    child.setParent(null);
    getChildren().remove(child);
  }
}