Program: 25195
Project: 25195
Buggy source:
/** 
 * Prepare statment on the database server
 * @param pContext query context
 * @param calledForEstimate set this to true if this call will use the estimate connection pool
 * @param checkConfigured set this to true if this call needs to check whether JDBC driver is configured
 * @param metricCallStack stack for metrics API
 * @return prepared statement
 * @throws LensException
 */
private PreparedStatement prepareInternal(AbstractQueryContext pContext,boolean calledForEstimate,boolean checkConfigured,String metricCallStack) throws LensException {
  if (checkConfigured) {
    if (pContext.getDriverQuery(this) == null) {
      throw new NullPointerException("String_Node_Str" + pContext.getUserQuery());
    }
    checkConfigured();
  }
  MethodMetricsContext sqlRewriteGauge=MethodMetricsFactory.createMethodGauge(pContext.getDriverConf(this),true,metricCallStack + COLUMNAR_SQL_REWRITE_GAUGE);
  String rewrittenQuery=rewriteQuery(pContext);
  sqlRewriteGauge.markSuccess();
  MethodMetricsContext jdbcPrepareGauge=MethodMetricsFactory.createMethodGauge(pContext.getDriverConf(this),true,metricCallStack + JDBC_PREPARE_GAUGE);
  PreparedStatement stmt=null;
  Connection conn=null;
  try {
    conn=calledForEstimate ? getEstimateConnection() : getConnection();
    stmt=conn.prepareStatement(rewrittenQuery);
    if (stmt.getWarnings() != null) {
      throw new LensException(stmt.getWarnings());
    }
  }
 catch (  SQLException sql) {
    handleJDBCSQLException(sql);
  }
 finally {
    if (conn != null) {
      try {
        conn.close();
      }
 catch (      SQLException e) {
        log.error("String_Node_Str",rewrittenQuery,e);
      }
    }
    jdbcPrepareGauge.markSuccess();
  }
  log.info("String_Node_Str",rewrittenQuery);
  return stmt;
}

Fixed version (ground truth):
/** 
 * Prepare statment on the database server
 * @param pContext query context
 * @param calledForEstimate set this to true if this call will use the estimate connection pool
 * @param checkConfigured set this to true if this call needs to check whether JDBC driver is configured
 * @param metricCallStack stack for metrics API
 * @return prepared statement
 * @throws LensException
 */
private PreparedStatement prepareInternal(AbstractQueryContext pContext,boolean calledForEstimate,boolean checkConfigured,String metricCallStack) throws LensException {
  if (checkConfigured) {
    if (pContext.getDriverQuery(this) == null) {
      throw new NullPointerException("String_Node_Str" + pContext.getUserQuery());
    }
    checkConfigured();
  }
  MethodMetricsContext sqlRewriteGauge=MethodMetricsFactory.createMethodGauge(pContext.getDriverConf(this),true,metricCallStack + COLUMNAR_SQL_REWRITE_GAUGE);
  String rewrittenQuery=rewriteQuery(pContext);
  sqlRewriteGauge.markSuccess();
  MethodMetricsContext jdbcPrepareGauge=MethodMetricsFactory.createMethodGauge(pContext.getDriverConf(this),true,metricCallStack + JDBC_PREPARE_GAUGE);
  PreparedStatement stmt=null;
  Connection conn=null;
  try {
    conn=calledForEstimate ? getEstimateConnection() : getConnection();
    stmt=conn.prepareStatement(rewrittenQuery);
    if (!pContext.getDriverConf(this).getBoolean(JDBC_VALIDATE_SKIP_WARNINGS,DEFAULT_JDBC_VALIDATE_SKIP_WARNINGS) && stmt.getWarnings() != null) {
      throw new LensException(stmt.getWarnings());
    }
  }
 catch (  SQLException sql) {
    handleJDBCSQLException(sql);
  }
 finally {
    if (conn != null) {
      try {
        conn.close();
      }
 catch (      SQLException e) {
        log.error("String_Node_Str",rewrittenQuery,e);
      }
    }
    jdbcPrepareGauge.markSuccess();
  }
  log.info("String_Node_Str",rewrittenQuery);
  return stmt;
}