Program: 91133
Project: 91133
Buggy source:
/** 
 * Creates a prov entity using the given entity Id. First queries the exe_entity table to get the type of the entity and then queries the relevant table to get further information.
 * @param entityId - entity Id in the database
 * @return Entity instance or null if there's no such entity
 */
protected Entity createEntity(String entityId,Connection connection) throws SQLException {
  assert(entityId != null);
  l.debug("String_Node_Str");
  PreparedStatement stmt=null;
  ResultSet resultSet=null;
  Entity entity=null;
  try {
    stmt=connection.prepareStatement(PROVSqlQuery.GET_ENTITY_TYPE);
    stmt.setString(1,entityId);
    resultSet=stmt.executeQuery();
    String entityType;
    if (resultSet.next()) {
      entityType=resultSet.getString("String_Node_Str");
    }
 else {
      return null;
    }
    if (stmt != null) {
      stmt.close();
      stmt=null;
    }
    if (resultSet != null) {
      resultSet.close();
      resultSet=null;
    }
    if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.FILE.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_FILE_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String fileURI=resultSet.getString("String_Node_Str");
        String size=resultSet.getString("String_Node_Str");
        String creationDate=resultSet.getString("String_Node_Str");
        String fileName=resultSet.getString("String_Node_Str");
        String md5=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.FILE_IDENTIFIER + entityId,fileURI,QueryConstants.ENTITY_FILE);
        Other sizeAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),size,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,sizeAtt);
        Other dateAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),creationDate,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,dateAtt);
        Other nameAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),fileName,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,nameAtt);
        Other md5Att=pFactory.newOther(getKomaduAttQName("String_Node_Str"),md5,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,md5Att);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.BLOCK.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_BLOCK_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String blockUri=resultSet.getString("String_Node_Str");
        String size=resultSet.getString("String_Node_Str");
        String blockContent=resultSet.getString("String_Node_Str");
        String md5=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.BLOCK_IDENTIFIER + entityId,blockUri,QueryConstants.ENTITY_BLOCK);
        Other sizeAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),size,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,sizeAtt);
        Other contentAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),blockContent,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,contentAtt);
        Other md5Att=pFactory.newOther(getKomaduAttQName("String_Node_Str"),md5,Name.QNAME_XSD_STRING);
        pFactory.addAttribute(entity,md5Att);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.COLLECTION.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_COLLECTION_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String collectionUri=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.COLLECTION_IDENTIFIER + entityId,collectionUri,QueryConstants.ENTITY_COLLECTION);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.GENERIC.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_GENERIC_ENTITY_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String genericEntityUri=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.FILE_IDENTIFIER + entityId,genericEntityUri,QueryConstants.ENTITY_BLOCK);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
    l.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    l.error("String_Node_Str");
    l.error(e.toString());
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    if (resultSet != null) {
      resultSet.close();
    }
  }
  return entity;
}

Fixed version (ground truth):
/** 
 * Creates a prov entity using the given entity Id. First queries the exe_entity table to get the type of the entity and then queries the relevant table to get further information.
 * @param entityId - entity Id in the database
 * @return Entity instance or null if there's no such entity
 */
protected Entity createEntity(String entityId,Connection connection) throws SQLException {
  assert(entityId != null);
  l.debug("String_Node_Str");
  PreparedStatement stmt=null;
  ResultSet resultSet=null;
  Entity entity=null;
  try {
    stmt=connection.prepareStatement(PROVSqlQuery.GET_ENTITY_TYPE);
    stmt.setString(1,entityId);
    resultSet=stmt.executeQuery();
    String entityType;
    if (resultSet.next()) {
      entityType=resultSet.getString("String_Node_Str");
    }
 else {
      return null;
    }
    if (stmt != null) {
      stmt.close();
      stmt=null;
    }
    if (resultSet != null) {
      resultSet.close();
      resultSet=null;
    }
    if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.FILE.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_FILE_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String fileURI=resultSet.getString("String_Node_Str");
        String size=resultSet.getString("String_Node_Str");
        String creationDate=resultSet.getString("String_Node_Str");
        String fileName=resultSet.getString("String_Node_Str");
        String md5=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.FILE_IDENTIFIER + entityId,fileURI,QueryConstants.ENTITY_FILE);
        if (size != null) {
          Other sizeAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),size,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,sizeAtt);
        }
        if (creationDate != null) {
          Other dateAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),creationDate,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,dateAtt);
        }
        if (fileName != null) {
          Other nameAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),fileName,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,nameAtt);
        }
        if (md5 != null) {
          Other md5Att=pFactory.newOther(getKomaduAttQName("String_Node_Str"),md5,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,md5Att);
        }
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.BLOCK.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_BLOCK_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String blockUri=resultSet.getString("String_Node_Str");
        String size=resultSet.getString("String_Node_Str");
        String blockContent=resultSet.getString("String_Node_Str");
        String md5=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.BLOCK_IDENTIFIER + entityId,blockUri,QueryConstants.ENTITY_BLOCK);
        if (size != null) {
          Other sizeAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),size,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,sizeAtt);
        }
        if (blockContent != null) {
          Other contentAtt=pFactory.newOther(getKomaduAttQName("String_Node_Str"),blockContent,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,contentAtt);
        }
        if (md5 != null) {
          Other md5Att=pFactory.newOther(getKomaduAttQName("String_Node_Str"),md5,Name.QNAME_XSD_STRING);
          pFactory.addAttribute(entity,md5Att);
        }
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.COLLECTION.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_COLLECTION_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String collectionUri=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.COLLECTION_IDENTIFIER + entityId,collectionUri,QueryConstants.ENTITY_COLLECTION);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
 else     if (entityType.equals(BaseDBIngesterImplementer.EntityTypeEnum.GENERIC.name())) {
      stmt=connection.prepareStatement(PROVSqlQuery.GET_GENERIC_ENTITY_BY_ID);
      stmt.setString(1,entityId);
      resultSet=stmt.executeQuery();
      while (resultSet.next()) {
        String genericEntityUri=resultSet.getString("String_Node_Str");
        entity=newEntity(QueryConstants.FILE_IDENTIFIER + entityId,genericEntityUri,QueryConstants.ENTITY_BLOCK);
        addCustomAttributes(PROVSqlQuery.GET_EXE_ENTITY_ATTRIBUTES_BY_ID,entityId,entity,connection);
      }
      if (stmt != null) {
        stmt.close();
        stmt=null;
      }
      if (resultSet != null) {
        resultSet.close();
        resultSet=null;
      }
    }
    l.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    l.error("String_Node_Str");
    l.error(e.toString());
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    if (resultSet != null) {
      resultSet.close();
    }
  }
  return entity;
}