Program: 149590
Project: 149590
Buggy source:
/** 
 * Load a correlation curve from file. Will set the global gr, peakDensity and spatialDomain variables. If the data fails to be loaded then the method will return false.
 * @return True if loaded
 */
private boolean loadCorrelationCurve(){
  inputFilename=Utils.getFilename("String_Node_Str",inputFilename);
  if (inputFilename == null)   return false;
  boolean spatialDomainSet=false;
  boolean peakDensitySet=false;
  BufferedReader input=null;
  try {
    FileInputStream fis=new FileInputStream(inputFilename);
    input=new BufferedReader(new UnicodeReader(fis,null));
    String line;
    int count=0;
    Pattern pattern=Pattern.compile("String_Node_Str");
    while ((line=input.readLine()) != null) {
      count++;
      if (line.length() == 0)       continue;
      if (line.charAt(0) != '#') {
        break;
      }
      Matcher match=pattern.matcher(line);
      if (match.find()) {
        if (match.group(1).equals(HEADER_SPATIAL_DOMAIN)) {
          spatialDomainSet=true;
          if (match.group(2).equalsIgnoreCase("String_Node_Str"))           spatialDomain=true;
 else           if (match.group(2).equalsIgnoreCase("String_Node_Str"))           spatialDomain=false;
 else           spatialDomainSet=false;
        }
 else         if (match.group(1).equals(HEADER_PEAK_DENSITY)) {
          try {
            peakDensity=Double.parseDouble(match.group(2));
            peakDensitySet=true;
          }
 catch (          NumberFormatException e) {
          }
        }
      }
    }
    if (!peakDensitySet) {
      IJ.error(TITLE,"String_Node_Str" + HEADER_PEAK_DENSITY + "String_Node_Str"+ inputFilename);
      return false;
    }
    if (!spatialDomainSet) {
      IJ.error(TITLE,"String_Node_Str" + HEADER_SPATIAL_DOMAIN + "String_Node_Str"+ inputFilename);
      return false;
    }
    ArrayList<double[]> data=new ArrayList<double[]>();
    while (line != null) {
      if (line.length() == 0)       continue;
      if (line.charAt(0) == '#')       continue;
      Scanner scanner=new Scanner(line);
      scanner.useDelimiter("String_Node_Str");
      double r, g;
      try {
        r=scanner.nextDouble();
        g=scanner.nextDouble();
      }
 catch (      InputMismatchException e) {
        IJ.error(TITLE,"String_Node_Str" + count);
        return false;
      }
catch (      NoSuchElementException e) {
        IJ.error(TITLE,"String_Node_Str" + count);
        return false;
      }
      double error=0;
      try {
        error=scanner.nextDouble();
      }
 catch (      InputMismatchException e) {
      }
catch (      NoSuchElementException e) {
      }
      data.add(new double[]{r,g,error});
      line=input.readLine();
      count++;
    }
    if (data.isEmpty()) {
      IJ.error(TITLE,"String_Node_Str" + inputFilename);
      return false;
    }
    gr=new double[3][data.size()];
    for (int i=0; i < data.size(); i++) {
      final double[] d=data.get(i);
      gr[0][i]=d[0];
      gr[1][i]=d[1];
      gr[2][i]=d[2];
    }
  }
 catch (  IOException e) {
    IJ.error(TITLE,"String_Node_Str" + inputFilename);
    return false;
  }
 finally {
    try {
      if (input != null)       input.close();
    }
 catch (    IOException e) {
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Load a correlation curve from file. Will set the global gr, peakDensity and spatialDomain variables. If the data fails to be loaded then the method will return false.
 * @return True if loaded
 */
private boolean loadCorrelationCurve(){
  inputFilename=Utils.getFilename("String_Node_Str",inputFilename);
  if (inputFilename == null)   return false;
  boolean spatialDomainSet=false;
  boolean peakDensitySet=false;
  BufferedReader input=null;
  try {
    FileInputStream fis=new FileInputStream(inputFilename);
    input=new BufferedReader(new UnicodeReader(fis,null));
    String line;
    int count=0;
    Pattern pattern=Pattern.compile("String_Node_Str");
    while ((line=input.readLine()) != null) {
      count++;
      if (line.length() == 0)       continue;
      if (line.charAt(0) != '#') {
        break;
      }
      Matcher match=pattern.matcher(line);
      if (match.find()) {
        if (match.group(1).equals(HEADER_SPATIAL_DOMAIN)) {
          spatialDomainSet=true;
          if (match.group(2).equalsIgnoreCase("String_Node_Str"))           spatialDomain=true;
 else           if (match.group(2).equalsIgnoreCase("String_Node_Str"))           spatialDomain=false;
 else           spatialDomainSet=false;
        }
 else         if (match.group(1).equals(HEADER_PEAK_DENSITY)) {
          try {
            peakDensity=Double.parseDouble(match.group(2));
            peakDensitySet=true;
          }
 catch (          NumberFormatException e) {
          }
        }
      }
    }
    if (!peakDensitySet) {
      IJ.error(TITLE,"String_Node_Str" + HEADER_PEAK_DENSITY + "String_Node_Str"+ inputFilename);
      return false;
    }
    if (!spatialDomainSet) {
      IJ.error(TITLE,"String_Node_Str" + HEADER_SPATIAL_DOMAIN + "String_Node_Str"+ inputFilename);
      return false;
    }
    ArrayList<double[]> data=new ArrayList<double[]>();
    while (line != null) {
      if (line.length() == 0)       continue;
      if (line.charAt(0) == '#')       continue;
      Scanner scanner=new Scanner(line);
      scanner.useDelimiter("String_Node_Str");
      double r, g;
      try {
        r=scanner.nextDouble();
        g=scanner.nextDouble();
      }
 catch (      InputMismatchException e) {
        IJ.error(TITLE,"String_Node_Str" + count);
        scanner.close();
        return false;
      }
catch (      NoSuchElementException e) {
        IJ.error(TITLE,"String_Node_Str" + count);
        scanner.close();
        return false;
      }
      double error=0;
      try {
        error=scanner.nextDouble();
      }
 catch (      InputMismatchException e) {
      }
catch (      NoSuchElementException e) {
      }
      scanner.close();
      data.add(new double[]{r,g,error});
      line=input.readLine();
      count++;
    }
    if (data.isEmpty()) {
      IJ.error(TITLE,"String_Node_Str" + inputFilename);
      return false;
    }
    gr=new double[3][data.size()];
    for (int i=0; i < data.size(); i++) {
      final double[] d=data.get(i);
      gr[0][i]=d[0];
      gr[1][i]=d[1];
      gr[2][i]=d[2];
    }
  }
 catch (  IOException e) {
    IJ.error(TITLE,"String_Node_Str" + inputFilename);
    return false;
  }
 finally {
    try {
      if (input != null)       input.close();
    }
 catch (    IOException e) {
    }
  }
  return true;
}