Program: 47075
Project: 47075
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() && !thumbOnly) {
    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() != null && 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);
            String channels=ah.getChannels().toLowerCase(Locale.ROOT);
            if (StringUtils.isNotBlank(channels)) {
              if (channels.equals("String_Node_Str") || channels.contains("String_Node_Str")) {
                audio.getAudioProperties().setNumberOfChannels(1);
              }
 else               if (!(channels.equals("String_Node_Str") || channels.equals("String_Node_Str") || channels.contains("String_Node_Str"))) {
                try {
                  audio.getAudioProperties().setNumberOfChannels(Integer.parseInt(channels));
                }
 catch (                IllegalArgumentException e) {
                  LOGGER.debug("String_Node_Str",channels);
                }
              }
            }
            if (StringUtils.isNotBlank(ah.getEncodingType())) {
              audio.setCodecA(ah.getEncodingType());
            }
            if (audio.getCodecA() != null && 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().equals(CoverSupplier.NONE)) {
                thumb=CoverUtil.get().getThumbnail(t);
              }
            }
            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());
              }
            }
            int thumbnailWidth=renderer.isSquareAudioThumbnails() ? renderer.getThumbnailHeight() : renderer.getThumbnailWidth();
            int thumbnailHeight=renderer.getThumbnailHeight();
            boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
            thumb=ImagesUtil.scaleImage(thumb,thumbnailWidth,thumbnailHeight,isFullyPlayedThumbnail,renderer);
            if (isFullyPlayedThumbnail) {
              thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.AUDIO);
            }
          }
        }
 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 (StringUtils.isBlank(container) && ext != null) {
          if (ext.getIdentifier() == Identifier.ADPCM) {
            audio.setCodecA(FormatConfiguration.ADPCM);
          }
 else           if (ext.getIdentifier() == Identifier.DSD) {
            audio.setCodecA(FormatConfiguration.DSDAudio);
          }
        }
        if (StringUtils.isNotBlank(audio.getSongname())) {
          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 (StringUtils.isBlank(container)) {
        container=audio.getCodecA();
      }
    }
    if (type == Format.IMAGE && file != null) {
      if (!thumbOnly) {
        try {
          ffmpeg_parsing=false;
          ImagesUtil.parseImageByImaging(file,this);
          container=codecV;
          imageCount++;
        }
 catch (        IOException|ImageReadException e) {
          LOGGER.debug("String_Node_Str",file.getAbsolutePath());
          ffmpeg_parsing=true;
        }
      }
      if (configuration.isThumbnailGenerationEnabled() && configuration.getImageThumbnailsEnabled() && thumbOnly) {
        LOGGER.trace("String_Node_Str",file.getName());
        try {
          int thumbnailWidth=renderer.isSquareImageThumbnails() ? renderer.getThumbnailHeight() : renderer.getThumbnailWidth();
          int thumbnailHeight=renderer.getThumbnailHeight();
          boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
          thumb=ImagesUtil.scaleImage(Files.readAllBytes(file.toPath()),thumbnailWidth,thumbnailHeight,isFullyPlayedThumbnail,renderer);
          if (isFullyPlayedThumbnail) {
            thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.IMAGE);
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str",file.getName(),e.getMessage());
          LOGGER.trace("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");
      }
synchronized (ffmpeg_failureLock) {
        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,renderer);
          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;
        int sz=0;
        try {
          is=pw.getInputStream(0);
          try {
            if (is != null) {
              sz=is.available();
              if (sz > 0) {
                thumb=new byte[sz];
                is.read(thumb);
              }
            }
          }
  finally {
            if (is != null) {
              is.close();
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e.getMessage());
          LOGGER.trace("String_Node_Str",e);
        }
        boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
        thumb=ImagesUtil.scaleImage(thumb,renderer.getThumbnailWidth(),renderer.getThumbnailHeight(),isFullyPlayedThumbnail,renderer);
        if (isFullyPlayedThumbnail) {
          thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.VIDEO);
        }
      }
    }
    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() && !thumbOnly) {
    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() != null && 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);
            String channels=ah.getChannels().toLowerCase(Locale.ROOT);
            if (StringUtils.isNotBlank(channels)) {
              if (channels.equals("String_Node_Str") || channels.contains("String_Node_Str")) {
                audio.getAudioProperties().setNumberOfChannels(1);
              }
 else               if (!(channels.equals("String_Node_Str") || channels.equals("String_Node_Str") || channels.contains("String_Node_Str"))) {
                try {
                  audio.getAudioProperties().setNumberOfChannels(Integer.parseInt(channels));
                }
 catch (                IllegalArgumentException e) {
                  LOGGER.debug("String_Node_Str",channels);
                }
              }
            }
            if (StringUtils.isNotBlank(ah.getEncodingType())) {
              audio.setCodecA(ah.getEncodingType());
            }
            if (audio.getCodecA() != null && 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().equals(CoverSupplier.NONE)) {
              thumb=CoverUtil.get().getThumbnail(t);
            }
            if (thumb != null) {
              thumbready=true;
            }
            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());
              }
            }
            int thumbnailWidth=renderer.isSquareAudioThumbnails() ? renderer.getThumbnailHeight() : renderer.getThumbnailWidth();
            int thumbnailHeight=renderer.getThumbnailHeight();
            boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
            thumb=ImagesUtil.scaleImage(thumb,thumbnailWidth,thumbnailHeight,isFullyPlayedThumbnail,renderer);
            if (isFullyPlayedThumbnail) {
              thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.AUDIO);
            }
          }
        }
 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 (StringUtils.isBlank(container) && ext != null) {
          if (ext.getIdentifier() == Identifier.ADPCM) {
            audio.setCodecA(FormatConfiguration.ADPCM);
          }
 else           if (ext.getIdentifier() == Identifier.DSD) {
            audio.setCodecA(FormatConfiguration.DSDAudio);
          }
        }
        if (StringUtils.isNotBlank(audio.getSongname())) {
          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 (StringUtils.isBlank(container)) {
        container=audio.getCodecA();
      }
    }
    if (type == Format.IMAGE && file != null) {
      if (!thumbOnly) {
        try {
          ffmpeg_parsing=false;
          ImagesUtil.parseImageByImaging(file,this);
          container=codecV;
          imageCount++;
        }
 catch (        IOException|ImageReadException e) {
          LOGGER.debug("String_Node_Str",file.getAbsolutePath());
          ffmpeg_parsing=true;
        }
      }
      if (configuration.isThumbnailGenerationEnabled() && configuration.getImageThumbnailsEnabled() && thumbOnly) {
        LOGGER.trace("String_Node_Str",file.getName());
        try {
          int thumbnailWidth=renderer.isSquareImageThumbnails() ? renderer.getThumbnailHeight() : renderer.getThumbnailWidth();
          int thumbnailHeight=renderer.getThumbnailHeight();
          boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
          thumb=ImagesUtil.scaleImage(Files.readAllBytes(file.toPath()),thumbnailWidth,thumbnailHeight,isFullyPlayedThumbnail,renderer);
          if (isFullyPlayedThumbnail) {
            thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.IMAGE);
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str",file.getName(),e.getMessage());
          LOGGER.trace("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");
      }
synchronized (ffmpeg_failureLock) {
        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,renderer);
          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;
        int sz=0;
        try {
          is=pw.getInputStream(0);
          try {
            if (is != null) {
              sz=is.available();
              if (sz > 0) {
                thumb=new byte[sz];
                is.read(thumb);
              }
            }
          }
  finally {
            if (is != null) {
              is.close();
            }
          }
        }
 catch (        IOException e) {
          LOGGER.debug("String_Node_Str" + e.getMessage());
          LOGGER.trace("String_Node_Str",e);
        }
        boolean isFullyPlayedThumbnail=FullyPlayed.isFullyPlayedThumbnail(file);
        thumb=ImagesUtil.scaleImage(thumb,renderer.getThumbnailWidth(),renderer.getThumbnailHeight(),isFullyPlayedThumbnail,renderer);
        if (isFullyPlayedThumbnail) {
          thumb=FullyPlayed.addFullyPlayedOverlay(thumb,MediaType.VIDEO);
        }
      }
    }
    finalize(type,inputFile);
    mediaparsed=true;
  }
}