Program: 25474
Project: 25474
Buggy source:
/** 
 * Refresh financial statements from websites (Tong Da Xin or Tong Hua Shun)
 * @throws java.io.IOException
 * @throws SQLException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void refreshFinData() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException, IOException {
  Connection con=jdbcConnection();
  String code;
  java.util.Date cDate=new java.util.Date();
  int id, currentYear=cDate.getYear() + 1900, currentMonth=cDate.getMonth() + 1;
  PreparedStatement pInsertPLNF, pInsertBSNF, pInsertCFNF, pInsertPLF, pInsertBSF, pInsertCFF, pInsertProvision, pInsert, pUpdateStock=con.prepareStatement("String_Node_Str");
  con.setAutoCommit(false);
  Statement sStock=con.createStatement();
  Statement sCreateFinData=con.createStatement();
  sStock.execute("String_Node_Str");
  sStock.execute("String_Node_Str");
  con.commit();
  TreeMap<String,Integer> stocksToUpdateReportDates=new TreeMap<>();
  ResultSet rs;
  FinancialSheet sheet;
  int aYear, order, latestYear, latestSeason, cYear=-1;
  System.out.println("String_Node_Str" + currentYear + "String_Node_Str"+ currentMonth / 3);
  rs=sStock.executeQuery("String_Node_Str" + (currentYear * 12 + currentMonth / 3 * 3) + "String_Node_Str");
  short cSeason=-1;
  boolean someSheetsAreEmpty;
  boolean isFinancial;
  Iterator<String> it;
  pInsertPLNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertBSNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertCFNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertPLF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertBSF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertCFF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertProvision=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  EnumMap<SheetType,PreparedStatement> financialInsert=new EnumMap<>(SheetType.class);
  financialInsert.put(balance_sheet,pInsertBSF);
  financialInsert.put(profit_and_loss,pInsertPLF);
  financialInsert.put(cash_flow,pInsertCFF);
  financialInsert.put(provision,pInsertProvision);
  EnumMap<SheetType,PreparedStatement> nonFinancialInsert=new EnumMap<>(SheetType.class);
  nonFinancialInsert.put(balance_sheet,pInsertBSNF);
  nonFinancialInsert.put(profit_and_loss,pInsertPLNF);
  nonFinancialInsert.put(cash_flow,pInsertCFNF);
  nonFinancialInsert.put(provision,pInsertProvision);
  EnumMap<SheetType,PreparedStatement> insert;
  String name;
  Number v;
  while (rs.next()) {
    id=rs.getInt("String_Node_Str");
    code=rs.getString("String_Node_Str");
    latestYear=rs.getInt("String_Node_Str");
    latestSeason=rs.getInt("String_Node_Str");
    isFinancial=rs.getBoolean("String_Node_Str");
    insert=isFinancial ? financialInsert : nonFinancialInsert;
    System.out.println(code);
    System.out.println("String_Node_Str" + latestYear + "String_Node_Str"+ latestSeason);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.executeBatch();
    cYear=-1;
    cSeason=-1;
    for (aYear=latestYear; aYear <= currentYear; aYear++) {
      for (short aSeason=(short)1; aSeason <= 4; aSeason++) {
        if (aYear == latestYear && (aSeason <= latestSeason)) {
          continue;
        }
        if (aYear == currentYear && (currentMonth <= aSeason * 3)) {
          continue;
        }
        someSheetsAreEmpty=false;
        for (        SheetType sheetName : SheetType.values()) {
          System.out.println(code + "String_Node_Str" + aYear+ "String_Node_Str"+ aSeason+ "String_Node_Str"+ sheetName);
          pInsert=insert.get(sheetName);
          sheet=new Hexun2008FinancialSheet(code,sheetName,aYear,aSeason);
          it=sheet.getDatumNames();
          order=1;
          while (it.hasNext()) {
            name=it.next();
            v=sheet.getValue(name);
            if (v == null) {
              v=0;
            }
            pInsert.setObject(order,v);
            order++;
          }
          someSheetsAreEmpty=someSheetsAreEmpty || (order == 1 && (sheetName == balance_sheet || sheetName == cash_flow || sheetName == profit_and_loss));
          if (order < 5)           continue;
          pInsert.setInt(order,id);
          pInsert.setInt(order + 1,aYear);
          pInsert.setShort(order + 2,aSeason);
          try {
            pInsert.executeUpdate();
          }
 catch (          SQLException ex) {
            System.out.println(aYear + "String_Node_Str" + aSeason+ "String_Node_Str"+ sheetName+ "String_Node_Str"+ order);
            System.out.println(ex.getMessage());
          }
        }
        if (!someSheetsAreEmpty) {
          cYear=aYear;
          cSeason=aSeason;
        }
      }
    }
    if (cYear != -1 && cSeason != -1) {
      pUpdateStock.setInt(1,cYear);
      pUpdateStock.setShort(2,cSeason);
      pUpdateStock.setInt(3,id);
      pUpdateStock.executeUpdate();
      stocksToUpdateReportDates.put(code,id);
    }
    con.commit();
  }
  if (!stocksToUpdateReportDates.isEmpty()) {
    System.out.println("String_Node_Str");
    currentYear=new Date().getYear() + 1900;
    for (    Map.Entry<String,Integer> entry : stocksToUpdateReportDates.entrySet()) {
      refreshReportPubDatesForStockSH(con,entry.getKey(),entry.getValue(),currentYear);
    }
  }
}

Fixed version (ground truth):
/** 
 * Refresh financial statements from websites (Tong Da Xin or Tong Hua Shun)
 * @throws java.io.IOException
 * @throws SQLException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void refreshFinData() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException, IOException {
  Connection con=jdbcConnection();
  String code;
  java.util.Date cDate=new java.util.Date();
  int id, currentYear=cDate.getYear() + 1900, currentMonth=cDate.getMonth() + 1;
  PreparedStatement pInsertPLNF, pInsertBSNF, pInsertCFNF, pInsertPLF, pInsertBSF, pInsertCFF, pInsertProvision, pInsert, pUpdateStock=con.prepareStatement("String_Node_Str");
  con.setAutoCommit(false);
  Statement sStock=con.createStatement();
  Statement sCreateFinData=con.createStatement();
  sStock.execute("String_Node_Str");
  sStock.execute("String_Node_Str");
  con.commit();
  TreeMap<String,Integer> stocksToUpdateReportDates=new TreeMap<>();
  ResultSet rs;
  FinancialSheet sheet;
  int aYear, order, latestYear, latestSeason, cYear=-1;
  System.out.println("String_Node_Str" + currentYear + "String_Node_Str"+ currentMonth / 3);
  rs=sStock.executeQuery("String_Node_Str" + (currentYear * 12 + currentMonth / 3 * 3) + "String_Node_Str");
  short cSeason=-1;
  boolean someSheetsAreEmpty;
  boolean isFinancial;
  Iterator<String> it;
  pInsertPLNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertBSNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertCFNF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertPLF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertBSF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertCFF=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  pInsertProvision=con.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  EnumMap<SheetType,PreparedStatement> financialInsert=new EnumMap<>(SheetType.class);
  financialInsert.put(balance_sheet,pInsertBSF);
  financialInsert.put(profit_and_loss,pInsertPLF);
  financialInsert.put(cash_flow,pInsertCFF);
  financialInsert.put(provision,pInsertProvision);
  EnumMap<SheetType,PreparedStatement> nonFinancialInsert=new EnumMap<>(SheetType.class);
  nonFinancialInsert.put(balance_sheet,pInsertBSNF);
  nonFinancialInsert.put(profit_and_loss,pInsertPLNF);
  nonFinancialInsert.put(cash_flow,pInsertCFNF);
  nonFinancialInsert.put(provision,pInsertProvision);
  EnumMap<SheetType,PreparedStatement> insert;
  String name;
  Number v;
  while (rs.next()) {
    id=rs.getInt("String_Node_Str");
    code=rs.getString("String_Node_Str");
    latestYear=rs.getInt("String_Node_Str");
    latestSeason=rs.getInt("String_Node_Str");
    isFinancial=rs.getBoolean("String_Node_Str");
    insert=isFinancial ? financialInsert : nonFinancialInsert;
    System.out.println(code);
    System.out.println("String_Node_Str" + latestYear + "String_Node_Str"+ latestSeason);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.addBatch("String_Node_Str" + (latestYear * 10 + latestSeason) + "String_Node_Str"+ id);
    sCreateFinData.executeBatch();
    cYear=-1;
    cSeason=-1;
    for (aYear=latestYear; aYear <= currentYear; aYear++) {
      for (short aSeason=(short)1; aSeason <= 4; aSeason++) {
        if (aYear == latestYear && (aSeason <= latestSeason)) {
          continue;
        }
        if (aYear == currentYear && (currentMonth <= aSeason * 3)) {
          continue;
        }
        someSheetsAreEmpty=false;
        for (        SheetType sheetName : SheetType.values()) {
          System.out.println(code + "String_Node_Str" + aYear+ "String_Node_Str"+ aSeason+ "String_Node_Str"+ sheetName);
          pInsert=insert.get(sheetName);
          sheet=new Hexun2008FinancialSheet(code,sheetName,aYear,aSeason);
          it=sheet.getDatumNames();
          order=1;
          while (it.hasNext()) {
            name=it.next();
            v=sheet.getValue(name);
            if (v == null) {
              v=0;
            }
            pInsert.setObject(order,v);
            order++;
          }
          someSheetsAreEmpty=someSheetsAreEmpty || (order == 1 && (sheetName == balance_sheet || sheetName == cash_flow || sheetName == profit_and_loss));
          if (order < 5)           continue;
          pInsert.setInt(order,id);
          pInsert.setInt(order + 1,aYear);
          pInsert.setShort(order + 2,aSeason);
          try {
            pInsert.executeUpdate();
          }
 catch (          SQLException ex) {
            System.out.println(aYear + "String_Node_Str" + aSeason+ "String_Node_Str"+ sheetName+ "String_Node_Str"+ order);
            System.out.println(ex.getMessage());
          }
        }
        if (!someSheetsAreEmpty) {
          cYear=aYear;
          cSeason=aSeason;
        }
      }
    }
    if (cYear != -1 && cSeason != -1) {
      pUpdateStock.setInt(1,cYear);
      pUpdateStock.setShort(2,cSeason);
      pUpdateStock.setInt(3,id);
      pUpdateStock.executeUpdate();
      stocksToUpdateReportDates.put(code,id);
    }
    con.commit();
  }
  if (!stocksToUpdateReportDates.isEmpty()) {
    System.out.println("String_Node_Str");
    currentYear=new Date().getYear() + 1900;
    for (    Map.Entry<String,Integer> entry : stocksToUpdateReportDates.entrySet()) {
      refreshReportPubDatesForStock(con,entry.getKey(),entry.getValue(),currentYear);
    }
  }
}