Program: 47161
Project: 47161
Buggy source:
/** 
 * Parse media without using MediaInfo.
 */
public void parse(InputFile inputFile,Format ext,int type,boolean thumbOnly,boolean resume,RendererConfiguration renderer){
  int i=0;
  while (isParsing()) {
    if (i == 5) {
      mediaparsed=true;
      break;
    }
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    i++;
  }
  if (isMediaparsed()) {
    return;
  }
  if (inputFile != null) {
    File file=inputFile.getFile();
    if (file != null) {
      size=file.length();
    }
 else {
      size=inputFile.getSize();
    }
    ProcessWrapperImpl pw=null;
    boolean ffmpeg_parsing=true;
    if (type == Format.AUDIO || ext instanceof AudioAsVideo) {
      ffmpeg_parsing=false;
      DLNAMediaAudio audio=new DLNAMediaAudio();
      if (file != null) {
        try {
          AudioFile af=AudioFileIO.read(file);
          AudioHeader ah=af.getAudioHeader();
          if (ah != null && !thumbOnly) {
            int length=ah.getTrackLength();
            int rate=ah.getSampleRateAsNumber();
            if (ah.getEncodingType().toLowerCase().contains("String_Node_Str")) {
              audio.setBitsperSample(24);
            }
            audio.setSampleFrequency("String_Node_Str" + rate);
            durationSec=(double)length;
            bitrate=(int)ah.getBitRateAsNumber();
            audio.getAudioProperties().setNumberOfChannels(2);
            if (ah.getChannels() != null && ah.getChannels().toLowerCase().contains("String_Node_Str")) {
              audio.getAudioProperties().setNumberOfChannels(1);
            }
 else             if (ah.getChannels() != null && ah.getChannels().toLowerCase().contains("String_Node_Str")) {
              audio.getAudioProperties().setNumberOfChannels(2);
            }
 else             if (ah.getChannels() != null) {
              audio.getAudioProperties().setNumberOfChannels(Integer.parseInt(ah.getChannels()));
            }
            audio.setCodecA(ah.getEncodingType().toLowerCase());
            if (audio.getCodecA().contains("String_Node_Str")) {
              audio.setCodecA(audio.getCodecA().substring(0,audio.getCodecA().indexOf("String_Node_Str")).trim());
            }
          }
          Tag t=af.getTag();
          if (t != null) {
            if (t.getArtworkList().size() > 0) {
              thumb=t.getArtworkList().get(0).getBinaryData();
            }
 else {
              if (configuration.getAudioThumbnailMethod() > 0) {
                thumb=CoverUtil.get().getThumbnailFromArtistAlbum(configuration.getAudioThumbnailMethod() == 1 ? CoverUtil.AUDIO_AMAZON : CoverUtil.AUDIO_DISCOGS,audio.getArtist(),audio.getAlbum());
              }
            }
            if (!thumbOnly) {
              audio.setAlbum(t.getFirst(FieldKey.ALBUM));
              audio.setArtist(t.getFirst(FieldKey.ARTIST));
              audio.setSongname(t.getFirst(FieldKey.TITLE));
              String y=t.getFirst(FieldKey.YEAR);
              try {
                if (y.length() > 4) {
                  y=y.substring(0,4);
                }
                audio.setYear(Integer.parseInt(((y != null && y.length() > 0) ? y : "String_Node_Str")));
                y=t.getFirst(FieldKey.TRACK);
                audio.setTrack(Integer.parseInt(((y != null && y.length() > 0) ? y : "String_Node_Str")));
                audio.setGenre(t.getFirst(FieldKey.GENRE));
              }
 catch (              NumberFormatException|KeyNotFoundException e) {
                LOGGER.debug("String_Node_Str" + e.getMessage());
              }
            }
          }
        }
 catch (        CannotReadException|IOException|TagException|ReadOnlyFileException|InvalidAudioFrameException|NumberFormatException|KeyNotFoundException e) {
          LOGGER.debug("String_Node_Str",e.getMessage(),e.getCause() != null ? e.getCause().getMessage() : "String_Node_Str");
          ffmpeg_parsing=false;
        }
        if (audio.getSongname() != null && audio.getSongname().length() > 0) {
          if (renderer != null && renderer.isPrependTrackNumbers() && audio.getTrack() > 0) {
            audio.setSongname(audio.getTrack() + "String_Node_Str" + audio.getSongname());
          }
        }
 else {
          audio.setSongname(file.getName());
        }
        if (!ffmpeg_parsing) {
          audioTracks.add(audio);
        }
      }
    }
    if (type == Format.IMAGE && file != null) {
      try {
        ffmpeg_parsing=false;
        ImageInfo info=Sanselan.getImageInfo(file);
        width=info.getWidth();
        height=info.getHeight();
        bitsPerPixel=info.getBitsPerPixel();
        String formatName=info.getFormatName();
        if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
          IImageMetadata meta=Sanselan.getMetadata(file);
          if (meta != null && meta instanceof JpegImageMetadata) {
            JpegImageMetadata jpegmeta=(JpegImageMetadata)meta;
            TiffField tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_MODEL);
            if (tf != null) {
              model=tf.getStringValue().trim();
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_EXPOSURE_TIME);
            if (tf != null) {
              exposure=(int)(1000 * tf.getDoubleValue());
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_ORIENTATION);
            if (tf != null) {
              orientation=tf.getIntValue();
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_ISO);
            if (tf != null) {
              int[] isoValues=tf.getIntArrayValue();
              iso=isoValues[0];
            }
          }
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
        container=codecV;
      }
 catch (      ImageReadException|IOException e) {
        LOGGER.info("String_Node_Str",file.getAbsolutePath());
      }
      if (configuration.getImageThumbnailsEnabled() && gen_thumb) {
        LOGGER.trace("String_Node_Str",file.getName());
        try {
          ByteArrayOutputStream out=new ByteArrayOutputStream();
          Thumbnails.of(file).size(320,180).outputFormat("String_Node_Str").outputQuality(1.0f).toOutputStream(out);
          thumb=out.toByteArray();
        }
 catch (        IOException|IllegalArgumentException|IllegalStateException e) {
          LOGGER.debug("String_Node_Str" + file.getName());
          LOGGER.debug("String_Node_Str" + e);
        }
      }
    }
    if (ffmpeg_parsing) {
      if (!thumbOnly || !configuration.isUseMplayerForVideoThumbs()) {
        pw=getFFmpegThumbnail(inputFile,resume,renderer);
      }
      boolean dvrms=false;
      String input="String_Node_Str";
      if (file != null) {
        input=ProcessUtil.getShortFileNameIfWideChars(file.getAbsolutePath());
        dvrms=file.getAbsolutePath().toLowerCase().endsWith("String_Node_Str");
      }
      if (pw != null && !ffmpeg_failure && !thumbOnly) {
        parseFFmpegInfo(pw.getResults(),input);
      }
      if (!thumbOnly && container != null && file != null && container.equals("String_Node_Str") && isH264() && getDurationInSeconds() == 0) {
        try {
          int length=MpegUtil.getDurationFromMpeg(file);
          if (length > 0) {
            durationSec=(double)length;
          }
        }
 catch (        IOException e) {
          LOGGER.trace("String_Node_Str" + e.getMessage());
        }
      }
      if (configuration.isUseMplayerForVideoThumbs() && type == Format.VIDEO && !dvrms) {
        try {
          getMplayerThumbnail(inputFile,resume);
          String frameName="String_Node_Str" + inputFile.hashCode();
          frameName=configuration.getTempFolder() + "String_Node_Str" + frameName+ "String_Node_Str";
          frameName=frameName.replace(',','_');
          File jpg=new File(frameName);
          if (jpg.exists()) {
            try (InputStream is=new FileInputStream(jpg)){
              int sz=is.available();
              if (sz > 0) {
                thumb=new byte[sz];
                is.read(thumb);
              }
            }
             if (!jpg.delete()) {
              jpg.deleteOnExit();
            }
            if (!jpg.getParentFile().delete() && !jpg.getParentFile().delete()) {
              LOGGER.debug("String_Node_Str" + jpg.getParentFile().getAbsolutePath() + "String_Node_Str");
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str",e);
        }
      }
      if (type == Format.VIDEO && pw != null && thumb == null) {
        InputStream is;
        try {
          int sz=0;
          is=pw.getInputStream(0);
          if (is != null) {
            sz=is.available();
            if (sz > 0) {
              thumb=new byte[sz];
              is.read(thumb);
            }
            is.close();
          }
          if (sz > 0 && !net.pms.PMS.isHeadless()) {
            BufferedImage image=ImageIO.read(new ByteArrayInputStream(thumb));
            if (image != null) {
              Graphics g=image.getGraphics();
              g.setColor(Color.WHITE);
              g.setFont(new Font("String_Node_Str",Font.PLAIN,14));
              int low=0;
              if (width > 0) {
                if (width == 1920 || width == 1440) {
                  g.drawString("String_Node_Str",0,low+=18);
                }
 else                 if (width == 1280) {
                  g.drawString("String_Node_Str",0,low+=18);
                }
              }
              ByteArrayOutputStream out=new ByteArrayOutputStream();
              ImageIO.write(image,"String_Node_Str",out);
              thumb=out.toByteArray();
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e.getMessage());
        }
      }
    }
    finalize(type,inputFile);
    mediaparsed=true;
  }
}

Fixed version (ground truth):
/** 
 * Parse media without using MediaInfo.
 */
public void parse(InputFile inputFile,Format ext,int type,boolean thumbOnly,boolean resume,RendererConfiguration renderer){
  int i=0;
  while (isParsing()) {
    if (i == 5) {
      mediaparsed=true;
      break;
    }
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    i++;
  }
  if (isMediaparsed()) {
    return;
  }
  if (inputFile != null) {
    File file=inputFile.getFile();
    if (file != null) {
      size=file.length();
    }
 else {
      size=inputFile.getSize();
    }
    ProcessWrapperImpl pw=null;
    boolean ffmpeg_parsing=true;
    if (type == Format.AUDIO || ext instanceof AudioAsVideo) {
      ffmpeg_parsing=false;
      DLNAMediaAudio audio=new DLNAMediaAudio();
      if (file != null) {
        try {
          AudioFile af=AudioFileIO.read(file);
          AudioHeader ah=af.getAudioHeader();
          if (ah != null && !thumbOnly) {
            int length=ah.getTrackLength();
            int rate=ah.getSampleRateAsNumber();
            if (ah.getEncodingType().toLowerCase().contains("String_Node_Str")) {
              audio.setBitsperSample(24);
            }
            audio.setSampleFrequency("String_Node_Str" + rate);
            durationSec=(double)length;
            bitrate=(int)ah.getBitRateAsNumber();
            audio.getAudioProperties().setNumberOfChannels(2);
            if (ah.getChannels() != null && ah.getChannels().toLowerCase().contains("String_Node_Str")) {
              audio.getAudioProperties().setNumberOfChannels(1);
            }
 else             if (ah.getChannels() != null && ah.getChannels().toLowerCase().contains("String_Node_Str")) {
              audio.getAudioProperties().setNumberOfChannels(2);
            }
 else             if (ah.getChannels() != null) {
              audio.getAudioProperties().setNumberOfChannels(Integer.parseInt(ah.getChannels()));
            }
            audio.setCodecA(ah.getEncodingType().toLowerCase());
            if (audio.getCodecA().contains("String_Node_Str")) {
              audio.setCodecA(audio.getCodecA().substring(0,audio.getCodecA().indexOf("String_Node_Str")).trim());
            }
          }
          Tag t=af.getTag();
          if (t != null) {
            if (t.getArtworkList().size() > 0) {
              thumb=t.getArtworkList().get(0).getBinaryData();
            }
 else {
              if (configuration.getAudioThumbnailMethod() > 0) {
                thumb=CoverUtil.get().getThumbnailFromArtistAlbum(configuration.getAudioThumbnailMethod() == 1 ? CoverUtil.AUDIO_AMAZON : CoverUtil.AUDIO_DISCOGS,audio.getArtist(),audio.getAlbum());
              }
            }
            if (!thumbOnly) {
              audio.setAlbum(t.getFirst(FieldKey.ALBUM));
              audio.setArtist(t.getFirst(FieldKey.ARTIST));
              audio.setSongname(t.getFirst(FieldKey.TITLE));
              String y=t.getFirst(FieldKey.YEAR);
              try {
                if (y.length() > 4) {
                  y=y.substring(0,4);
                }
                audio.setYear(Integer.parseInt(((y != null && y.length() > 0) ? y : "String_Node_Str")));
                y=t.getFirst(FieldKey.TRACK);
                audio.setTrack(Integer.parseInt(((y != null && y.length() > 0) ? y : "String_Node_Str")));
                audio.setGenre(t.getFirst(FieldKey.GENRE));
              }
 catch (              NumberFormatException|KeyNotFoundException e) {
                LOGGER.debug("String_Node_Str" + e.getMessage());
              }
            }
          }
        }
 catch (        CannotReadException|IOException|TagException|ReadOnlyFileException|InvalidAudioFrameException|NumberFormatException|KeyNotFoundException e) {
          LOGGER.debug("String_Node_Str",e.getMessage(),e.getCause() != null ? e.getCause().getMessage() : "String_Node_Str");
          ffmpeg_parsing=false;
        }
        if (audio.getSongname() != null && audio.getSongname().length() > 0) {
          if (renderer != null && renderer.isPrependTrackNumbers() && audio.getTrack() > 0) {
            audio.setSongname(audio.getTrack() + "String_Node_Str" + audio.getSongname());
          }
        }
 else {
          audio.setSongname(file.getName());
        }
        if (!ffmpeg_parsing) {
          audioTracks.add(audio);
        }
      }
    }
    if (type == Format.IMAGE && file != null) {
      try {
        ffmpeg_parsing=false;
        ImageInfo info=Sanselan.getImageInfo(file);
        width=info.getWidth();
        height=info.getHeight();
        bitsPerPixel=info.getBitsPerPixel();
        String formatName=info.getFormatName();
        if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
          IImageMetadata meta=Sanselan.getMetadata(file);
          if (meta != null && meta instanceof JpegImageMetadata) {
            JpegImageMetadata jpegmeta=(JpegImageMetadata)meta;
            TiffField tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_MODEL);
            if (tf != null) {
              model=tf.getStringValue().trim();
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_EXPOSURE_TIME);
            if (tf != null) {
              exposure=(int)(1000 * tf.getDoubleValue());
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_ORIENTATION);
            if (tf != null) {
              orientation=tf.getIntValue();
            }
            tf=jpegmeta.findEXIFValue(TiffConstants.EXIF_TAG_ISO);
            if (tf != null) {
              int[] isoValues=tf.getIntArrayValue();
              iso=isoValues[0];
            }
          }
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
 else         if (formatName.startsWith("String_Node_Str")) {
          codecV="String_Node_Str";
        }
        container=codecV;
        imageCount++;
      }
 catch (      ImageReadException|IOException e) {
        LOGGER.info("String_Node_Str",file.getAbsolutePath());
      }
      if (configuration.getImageThumbnailsEnabled() && gen_thumb) {
        LOGGER.trace("String_Node_Str",file.getName());
        try {
          ByteArrayOutputStream out=new ByteArrayOutputStream();
          Thumbnails.of(file).size(320,180).outputFormat("String_Node_Str").outputQuality(1.0f).toOutputStream(out);
          thumb=out.toByteArray();
        }
 catch (        IOException|IllegalArgumentException|IllegalStateException e) {
          LOGGER.debug("String_Node_Str" + file.getName());
          LOGGER.debug("String_Node_Str" + e);
        }
      }
    }
    if (ffmpeg_parsing) {
      if (!thumbOnly || !configuration.isUseMplayerForVideoThumbs()) {
        pw=getFFmpegThumbnail(inputFile,resume,renderer);
      }
      boolean dvrms=false;
      String input="String_Node_Str";
      if (file != null) {
        input=ProcessUtil.getShortFileNameIfWideChars(file.getAbsolutePath());
        dvrms=file.getAbsolutePath().toLowerCase().endsWith("String_Node_Str");
      }
      if (pw != null && !ffmpeg_failure && !thumbOnly) {
        parseFFmpegInfo(pw.getResults(),input);
      }
      if (!thumbOnly && container != null && file != null && container.equals("String_Node_Str") && isH264() && getDurationInSeconds() == 0) {
        try {
          int length=MpegUtil.getDurationFromMpeg(file);
          if (length > 0) {
            durationSec=(double)length;
          }
        }
 catch (        IOException e) {
          LOGGER.trace("String_Node_Str" + e.getMessage());
        }
      }
      if (configuration.isUseMplayerForVideoThumbs() && type == Format.VIDEO && !dvrms) {
        try {
          getMplayerThumbnail(inputFile,resume);
          String frameName="String_Node_Str" + inputFile.hashCode();
          frameName=configuration.getTempFolder() + "String_Node_Str" + frameName+ "String_Node_Str";
          frameName=frameName.replace(',','_');
          File jpg=new File(frameName);
          if (jpg.exists()) {
            try (InputStream is=new FileInputStream(jpg)){
              int sz=is.available();
              if (sz > 0) {
                thumb=new byte[sz];
                is.read(thumb);
              }
            }
             if (!jpg.delete()) {
              jpg.deleteOnExit();
            }
            if (!jpg.getParentFile().delete() && !jpg.getParentFile().delete()) {
              LOGGER.debug("String_Node_Str" + jpg.getParentFile().getAbsolutePath() + "String_Node_Str");
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str",e);
        }
      }
      if (type == Format.VIDEO && pw != null && thumb == null) {
        InputStream is;
        try {
          int sz=0;
          is=pw.getInputStream(0);
          if (is != null) {
            sz=is.available();
            if (sz > 0) {
              thumb=new byte[sz];
              is.read(thumb);
            }
            is.close();
          }
          if (sz > 0 && !net.pms.PMS.isHeadless()) {
            BufferedImage image=ImageIO.read(new ByteArrayInputStream(thumb));
            if (image != null) {
              Graphics g=image.getGraphics();
              g.setColor(Color.WHITE);
              g.setFont(new Font("String_Node_Str",Font.PLAIN,14));
              int low=0;
              if (width > 0) {
                if (width == 1920 || width == 1440) {
                  g.drawString("String_Node_Str",0,low+=18);
                }
 else                 if (width == 1280) {
                  g.drawString("String_Node_Str",0,low+=18);
                }
              }
              ByteArrayOutputStream out=new ByteArrayOutputStream();
              ImageIO.write(image,"String_Node_Str",out);
              thumb=out.toByteArray();
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e.getMessage());
        }
      }
    }
    finalize(type,inputFile);
    mediaparsed=true;
  }
}