Program: 84898
Project: 84898
Buggy source:
<T>List<List<String>> translateFieldsByIds(String language,EntityCacheEntry e,List<Object> ids,List<JpaEntityProperty<? super T,String>> fields){
  if (e.tt == null) {
    throw new IllegalArgumentException("String_Node_Str" + e.entityClass.getName());
  }
  language=language.toUpperCase();
  BundleInfo bi=e.tt.getBundle();
  boolean translate=!(bi.getPrimaryLanguage().getCode().equals("String_Node_Str"));
  if (translate) {
    checkLanguageIsSupported(bi,language);
  }
  List<List<String>> retval=new ArrayList<List<String>>();
  if (!translate) {
    for (    Object id : ids) {
      T entity=(T)getEntityManager().find(e.entityClass,id);
      List<String> row=new ArrayList<String>();
      for (      JpaEntityProperty<? super T,String> p : fields) {
        row.add(p.getValue(entity));
      }
      retval.add(row);
    }
  }
 else {
    Cache dataCache=getDataCache();
    String translatedTable=e.tt.getTranslationTableName();
    StringBuilder sqlBuilder=new StringBuilder();
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(e.tt.getPkColumnName());
    for (    JpaEntityProperty<? super T,String> p : fields) {
      sqlBuilder.append("String_Node_Str");
      String columnName=getTranslatedColumnName(p.getColumnName(),language);
      sqlBuilder.append(columnName);
    }
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(translatedTable);
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(e.tt.getPkColumnName());
    boolean doHack=false;
    JdbcConnectionWrapper wr=getJpaEx().getJdbcConnectionWrapper(getEntityManager(),true);
    Connection cn=wr.getConnection();
    try {
      if (cn.getMetaData().supportsMultipleResultSets() && cn.getMetaData().supportsBatchUpdates() && doHack) {
        sqlBuilder.append("String_Node_Str");
        String sql=sqlBuilder.toString();
        PreparedStatement st=cn.prepareStatement(sql);
        int i=0;
        HashMap<Integer,List<String>> cachedRows=new HashMap<Integer,List<String>>();
        for (        Object id : ids) {
          List<String> row=getCachedTranslation(id,e.entityClass,language,fields);
          if (row == null) {
            st.setObject(1,id);
            st.addBatch();
          }
 else {
            cachedRows.put(i,row);
          }
          ++i;
        }
        int[] results=st.executeBatch();
        Iterator it=ids.iterator();
        i=0;
        do {
          List<String> retvalRow=cachedRows.get(i);
          if (retvalRow == null) {
            Object id=it.next();
            ResultSet rs=st.getResultSet();
            retvalRow=new ArrayList<String>();
            if (!rs.next()) {
              T entity=(T)getEntityManager().find(e.entityClass,id);
              for (              JpaEntityProperty<? super T,String> p : fields) {
                retvalRow.add(p.getValue(entity));
              }
            }
 else {
              int nColumns=rs.getMetaData().getColumnCount();
              for (int ii=0; ii < nColumns; ++ii) {
                if (ii != 0) {
                  retvalRow.add(rs.getString(ii + 1));
                }
              }
            }
            putCachedTranslation(id,e.entityClass,language,fields,retvalRow);
          }
          retval.add(retvalRow);
          ++i;
        }
 while (st.getMoreResults());
      }
 else {
        sqlBuilder.append("String_Node_Str");
        boolean isFirst=true;
        int nAdded=0;
        Map<Object,Integer> indexesByIds=new HashMap<Object,Integer>();
        for (int i=0; i < ids.size(); ++i) {
          if (!isFirst) {
            sqlBuilder.append("String_Node_Str");
          }
          Object id=ids.get(i);
          List<String> row=getCachedTranslation(id,e.entityClass,language,fields);
          if (row == null) {
            sqlBuilder.append("String_Node_Str");
            isFirst=false;
            ++nAdded;
          }
        }
        sqlBuilder.append("String_Node_Str");
        if (nAdded != 0) {
          PreparedStatement st=cn.prepareStatement(sqlBuilder.toString());
          for (int i=0; i < ids.size(); ++i) {
            st.setObject(i + 1,ids.get(i));
            indexesByIds.put(ids.get(i),i);
            retval.add(new ArrayList<String>());
          }
          ResultSet rs=st.executeQuery();
          while (rs.next()) {
            Object rsid=rs.getObject(1);
            Integer rsind=indexesByIds.get(rsid);
            if (rsind == null) {
              throw new IllegalStateException("String_Node_Str");
            }
            List<String> retRow=retval.get(rsind);
            for (int i=0; i < fields.size(); ++i) {
              String value=rs.getString(i + 2);
              retRow.add(value);
            }
            putCachedTranslation(rsid,e.entityClass,language,fields,retRow);
          }
        }
        int i=0;
        for (        List<String> row : retval) {
          if (row.size() == 0) {
            List<String> crow=getCachedTranslation(ids.get(i),e.entityClass,language,fields);
            if (crow != null) {
              row.addAll(crow);
            }
 else {
              T entity=(T)getEntityManager().find(e.entityClass,ids.get(i));
              for (              JpaEntityProperty<? super T,String> p : fields) {
                row.add(p.getValue(entity));
              }
            }
          }
          ++i;
        }
      }
    }
 catch (    SQLException ex) {
      LOG.error("String_Node_Str" + ex.getErrorCode());
      SQLException currex=ex;
      while (currex != null) {
        LOG.error(currex.getMessage());
        currex=currex.getNextException();
      }
      throw new RuntimeSqlException(ex);
    }
 finally {
      wr.releaseConnection(cn);
    }
  }
  return retval;
}

Fixed version (ground truth):
<T>List<List<String>> translateFieldsByIds(String language,EntityCacheEntry e,List<Object> ids,List<JpaEntityProperty<? super T,String>> fields){
  if (e.tt == null) {
    throw new IllegalArgumentException("String_Node_Str" + e.entityClass.getName());
  }
  language=language.toUpperCase();
  BundleInfo bi=e.tt.getBundle();
  boolean translate=!(bi.getPrimaryLanguage().getCode().equals("String_Node_Str"));
  if (translate) {
    checkLanguageIsSupported(bi,language);
  }
  List<List<String>> retval=new ArrayList<List<String>>();
  if (!translate) {
    for (    Object id : ids) {
      T entity=(T)getEntityManager().find(e.entityClass,id);
      List<String> row=new ArrayList<String>();
      for (      JpaEntityProperty<? super T,String> p : fields) {
        row.add(p.getValue(entity));
      }
      retval.add(row);
    }
  }
 else {
    Cache dataCache=getDataCache();
    String translatedTable=e.tt.getTranslationTableName();
    StringBuilder sqlBuilder=new StringBuilder();
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(e.tt.getPkColumnName());
    for (    JpaEntityProperty<? super T,String> p : fields) {
      sqlBuilder.append("String_Node_Str");
      String columnName=getTranslatedColumnName(p.getColumnName(),language);
      sqlBuilder.append(columnName);
    }
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(translatedTable);
    sqlBuilder.append("String_Node_Str");
    sqlBuilder.append(e.tt.getPkColumnName());
    boolean doHack=false;
    JdbcConnectionWrapper wr=getJpaEx().getJdbcConnectionWrapper(getEntityManager(),true);
    Connection cn=wr.getConnection();
    try {
      if (cn.getMetaData().supportsMultipleResultSets() && cn.getMetaData().supportsBatchUpdates() && doHack) {
        sqlBuilder.append("String_Node_Str");
        String sql=sqlBuilder.toString();
        PreparedStatement st=cn.prepareStatement(sql);
        int i=0;
        HashMap<Integer,List<String>> cachedRows=new HashMap<Integer,List<String>>();
        for (        Object id : ids) {
          List<String> row=getCachedTranslation(id,e.entityClass,language,fields);
          if (row == null) {
            st.setObject(1,id);
            st.addBatch();
          }
 else {
            cachedRows.put(i,row);
          }
          ++i;
        }
        int[] results=st.executeBatch();
        Iterator it=ids.iterator();
        i=0;
        do {
          List<String> retvalRow=cachedRows.get(i);
          if (retvalRow == null) {
            Object id=it.next();
            ResultSet rs=st.getResultSet();
            retvalRow=new ArrayList<String>();
            if (!rs.next()) {
              T entity=(T)getEntityManager().find(e.entityClass,id);
              for (              JpaEntityProperty<? super T,String> p : fields) {
                retvalRow.add(p.getValue(entity));
              }
            }
 else {
              int nColumns=rs.getMetaData().getColumnCount();
              for (int ii=0; ii < nColumns; ++ii) {
                if (ii != 0) {
                  retvalRow.add(rs.getString(ii + 1));
                }
              }
            }
            putCachedTranslation(id,e.entityClass,language,fields,retvalRow);
          }
          retval.add(retvalRow);
          ++i;
        }
 while (st.getMoreResults());
      }
 else {
        sqlBuilder.append("String_Node_Str");
        boolean isFirst=true;
        int nAdded=0;
        Map<Object,Integer> indexesByIds=new HashMap<Object,Integer>();
        for (int i=0; i < ids.size(); ++i) {
          Object id=ids.get(i);
          List<String> row=getCachedTranslation(id,e.entityClass,language,fields);
          if (row == null) {
            if (!isFirst) {
              sqlBuilder.append("String_Node_Str");
            }
            sqlBuilder.append("String_Node_Str");
            isFirst=false;
            ++nAdded;
          }
        }
        sqlBuilder.append("String_Node_Str");
        if (nAdded != 0) {
          PreparedStatement st=cn.prepareStatement(sqlBuilder.toString());
          for (int i=0, j=0; i < ids.size(); ++i) {
            Object id=ids.get(i);
            List<String> row=getCachedTranslation(id,e.entityClass,language,fields);
            if (row == null) {
              st.setObject(++j,ids.get(i));
              indexesByIds.put(ids.get(i),i);
            }
            retval.add(new ArrayList<String>());
          }
          ResultSet rs=st.executeQuery();
          while (rs.next()) {
            Object rsid=rs.getObject(1);
            Integer rsind=indexesByIds.get(rsid);
            if (rsind == null) {
              throw new IllegalStateException("String_Node_Str");
            }
            List<String> retRow=retval.get(rsind);
            for (int i=0; i < fields.size(); ++i) {
              String value=rs.getString(i + 2);
              retRow.add(value);
            }
            putCachedTranslation(rsid,e.entityClass,language,fields,retRow);
          }
        }
 else {
          for (int i=0; i < ids.size(); ++i) {
            retval.add(new ArrayList<String>());
          }
        }
        int i=0;
        for (        List<String> row : retval) {
          if (row.size() == 0) {
            List<String> crow=getCachedTranslation(ids.get(i),e.entityClass,language,fields);
            if (crow != null) {
              row.addAll(crow);
            }
 else {
              T entity=(T)getEntityManager().find(e.entityClass,ids.get(i));
              for (              JpaEntityProperty<? super T,String> p : fields) {
                row.add(p.getValue(entity));
              }
            }
          }
          ++i;
        }
      }
    }
 catch (    SQLException ex) {
      LOG.error("String_Node_Str" + ex.getErrorCode());
      SQLException currex=ex;
      while (currex != null) {
        LOG.error(currex.getMessage());
        currex=currex.getNextException();
      }
      throw new RuntimeSqlException(ex);
    }
 finally {
      wr.releaseConnection(cn);
    }
  }
  return retval;
}