Program: 31667
Project: 31667
Buggy source:
/** 
 * Load model instance from input stream which is saved in NNOutput for specified binary format.
 * @param input the input stream, flat input stream or gzip input stream both OK
 * @param isRemoveNameSpace is remove name space or not
 * @return the nn model instance
 * @throws IOException any IOException in de-serialization.
 */
public static IndependentNNModel loadFromStream(InputStream input,boolean isRemoveNameSpace) throws IOException {
  DataInputStream dis=null;
  try {
    byte[] header=new byte[2];
    BufferedInputStream bis=new BufferedInputStream(input);
    bis.mark(2);
    int result=bis.read(header);
    bis.reset();
    int ss=(header[0] & 0xff) | ((header[1] & 0xff) << 8);
    if (result != -1 && ss == GZIPInputStream.GZIP_MAGIC) {
      dis=new DataInputStream(new GZIPInputStream(bis));
    }
 else {
      dis=new DataInputStream(bis);
    }
  }
 catch (  java.io.IOException e) {
    dis=new DataInputStream(input);
  }
  int version=dis.readInt();
  LOG.info("String_Node_Str" + version);
  IndependentNNModel.setVersion(version);
  String normStr=ml.shifu.shifu.core.dtrain.StringUtils.readString(dis);
  LOG.info("String_Node_Str" + normStr);
  NormType normType=NormType.valueOf(normStr.toUpperCase());
  Map<Integer,String> numNameMap=new HashMap<Integer,String>();
  Map<Integer,List<String>> cateColumnNameNames=new HashMap<Integer,List<String>>();
  Map<Integer,Map<String,Double>> cateWoeMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,Map<String,Double>> cateWgtWoeMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,Map<String,Double>> binPosRateMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,List<Double>> numerBinBoundaries=new HashMap<Integer,List<Double>>();
  Map<Integer,List<Double>> numerWoes=new HashMap<Integer,List<Double>>();
  Map<Integer,List<Double>> numerWgtWoes=new HashMap<Integer,List<Double>>();
  Map<Integer,Double> numerMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> numerStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> woeMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> woeStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> wgtWoeMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> wgtWoeStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> cutoffMap=new HashMap<Integer,Double>();
  int columnSize=dis.readInt();
  for (int i=0; i < columnSize; i++) {
    NNColumnStats cs=new NNColumnStats();
    cs.readFields(dis);
    List<Double> binWoes=cs.getBinCountWoes();
    List<Double> binWgtWoes=cs.getBinWeightWoes();
    List<Double> binPosRates=cs.getBinPosRates();
    int columnNum=cs.getColumnNum();
    if (isRemoveNameSpace) {
      numNameMap.put(columnNum,StringUtils.getSimpleColumnName(cs.getColumnName()));
    }
 else {
      numNameMap.put(columnNum,cs.getColumnName());
    }
    Map<String,Double> woeMap=new HashMap<String,Double>();
    Map<String,Double> woeWgtMap=new HashMap<String,Double>();
    Map<String,Double> posRateMap=new HashMap<String,Double>();
    if (cs.isCategorical()) {
      List<String> binCategories=cs.getBinCategories();
      cateColumnNameNames.put(columnNum,binCategories);
      for (int j=0; j < binCategories.size(); j++) {
        String currCate=binCategories.get(j);
        if (currCate.contains(Constants.CATEGORICAL_GROUP_VAL_DELIMITER)) {
          String[] splits=StringUtils.split(currCate,Constants.CATEGORICAL_GROUP_VAL_DELIMITER);
          for (          String str : splits) {
            woeMap.put(str,binWoes.get(j));
            woeWgtMap.put(str,binWgtWoes.get(j));
            posRateMap.put(str,binPosRates.get(j));
          }
        }
 else {
          woeMap.put(currCate,binWoes.get(j));
          woeWgtMap.put(currCate,binWgtWoes.get(j));
          posRateMap.put(currCate,binPosRates.get(j));
        }
      }
      woeMap.put(Constants.EMPTY_CATEGORY,binWoes.get(binCategories.size()));
      woeWgtMap.put(Constants.EMPTY_CATEGORY,binWgtWoes.get(binCategories.size()));
      posRateMap.put(Constants.EMPTY_CATEGORY,binPosRates.get(binCategories.size()));
    }
 else {
      numerBinBoundaries.put(columnNum,cs.getBinBoundaries());
      numerWoes.put(columnNum,binWoes);
      numerWgtWoes.put(columnNum,binWgtWoes);
    }
    cateWoeMap.put(columnNum,woeMap);
    cateWgtWoeMap.put(columnNum,woeWgtMap);
    binPosRateMap.put(columnNum,posRateMap);
    numerMeanMap.put(columnNum,cs.getMean());
    numerStddevMap.put(columnNum,cs.getStddev());
    woeMeanMap.put(columnNum,cs.getWoeMean());
    woeStddevMap.put(columnNum,cs.getWoeStddev());
    wgtWoeMeanMap.put(columnNum,cs.getWoeWgtMean());
    wgtWoeStddevMap.put(columnNum,cs.getWoeWgtStddev());
    cutoffMap.put(columnNum,cs.getCutoff());
  }
  Map<Integer,Integer> columnMap=new HashMap<Integer,Integer>();
  int columnMapSize=dis.readInt();
  for (int i=0; i < columnMapSize; i++) {
    columnMap.put(dis.readInt(),dis.readInt());
  }
  BasicFloatNetwork network=new PersistBasicFloatNetwork().readNetwork(dis);
  return new IndependentNNModel(network,normType,numNameMap,cateColumnNameNames,columnMap,cateWoeMap,cateWgtWoeMap,binPosRateMap,numerBinBoundaries,numerWgtWoes,numerWoes,cutoffMap,numerMeanMap,numerStddevMap,woeMeanMap,woeStddevMap,wgtWoeMeanMap,wgtWoeStddevMap);
}

Fixed version (ground truth):
/** 
 * Load model instance from input stream which is saved in NNOutput for specified binary format.
 * @param input the input stream, flat input stream or gzip input stream both OK
 * @param isRemoveNameSpace is remove name space or not
 * @return the nn model instance
 * @throws IOException any IOException in de-serialization.
 */
public static IndependentNNModel loadFromStream(InputStream input,boolean isRemoveNameSpace) throws IOException {
  DataInputStream dis=null;
  try {
    byte[] header=new byte[2];
    BufferedInputStream bis=new BufferedInputStream(input);
    bis.mark(2);
    int result=bis.read(header);
    bis.reset();
    int ss=(header[0] & 0xff) | ((header[1] & 0xff) << 8);
    if (result != -1 && ss == GZIPInputStream.GZIP_MAGIC) {
      dis=new DataInputStream(new GZIPInputStream(bis));
    }
 else {
      dis=new DataInputStream(bis);
    }
  }
 catch (  java.io.IOException e) {
    dis=new DataInputStream(input);
  }
  int version=dis.readInt();
  IndependentNNModel.setVersion(version);
  String normStr=ml.shifu.shifu.core.dtrain.StringUtils.readString(dis);
  NormType normType=NormType.valueOf(normStr.toUpperCase());
  Map<Integer,String> numNameMap=new HashMap<Integer,String>();
  Map<Integer,List<String>> cateColumnNameNames=new HashMap<Integer,List<String>>();
  Map<Integer,Map<String,Double>> cateWoeMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,Map<String,Double>> cateWgtWoeMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,Map<String,Double>> binPosRateMap=new HashMap<Integer,Map<String,Double>>();
  Map<Integer,List<Double>> numerBinBoundaries=new HashMap<Integer,List<Double>>();
  Map<Integer,List<Double>> numerWoes=new HashMap<Integer,List<Double>>();
  Map<Integer,List<Double>> numerWgtWoes=new HashMap<Integer,List<Double>>();
  Map<Integer,Double> numerMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> numerStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> woeMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> woeStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> wgtWoeMeanMap=new HashMap<Integer,Double>();
  Map<Integer,Double> wgtWoeStddevMap=new HashMap<Integer,Double>();
  Map<Integer,Double> cutoffMap=new HashMap<Integer,Double>();
  int columnSize=dis.readInt();
  for (int i=0; i < columnSize; i++) {
    NNColumnStats cs=new NNColumnStats();
    cs.readFields(dis);
    List<Double> binWoes=cs.getBinCountWoes();
    List<Double> binWgtWoes=cs.getBinWeightWoes();
    List<Double> binPosRates=cs.getBinPosRates();
    int columnNum=cs.getColumnNum();
    if (isRemoveNameSpace) {
      numNameMap.put(columnNum,StringUtils.getSimpleColumnName(cs.getColumnName()));
    }
 else {
      numNameMap.put(columnNum,cs.getColumnName());
    }
    Map<String,Double> woeMap=new HashMap<String,Double>();
    Map<String,Double> woeWgtMap=new HashMap<String,Double>();
    Map<String,Double> posRateMap=new HashMap<String,Double>();
    if (cs.isCategorical()) {
      List<String> binCategories=cs.getBinCategories();
      cateColumnNameNames.put(columnNum,binCategories);
      for (int j=0; j < binCategories.size(); j++) {
        String currCate=binCategories.get(j);
        if (currCate.contains(Constants.CATEGORICAL_GROUP_VAL_DELIMITER)) {
          String[] splits=StringUtils.split(currCate,Constants.CATEGORICAL_GROUP_VAL_DELIMITER);
          for (          String str : splits) {
            woeMap.put(str,binWoes.get(j));
            woeWgtMap.put(str,binWgtWoes.get(j));
            posRateMap.put(str,binPosRates.get(j));
          }
        }
 else {
          woeMap.put(currCate,binWoes.get(j));
          woeWgtMap.put(currCate,binWgtWoes.get(j));
          posRateMap.put(currCate,binPosRates.get(j));
        }
      }
      woeMap.put(Constants.EMPTY_CATEGORY,binWoes.get(binCategories.size()));
      woeWgtMap.put(Constants.EMPTY_CATEGORY,binWgtWoes.get(binCategories.size()));
      posRateMap.put(Constants.EMPTY_CATEGORY,binPosRates.get(binCategories.size()));
    }
 else {
      numerBinBoundaries.put(columnNum,cs.getBinBoundaries());
      numerWoes.put(columnNum,binWoes);
      numerWgtWoes.put(columnNum,binWgtWoes);
    }
    cateWoeMap.put(columnNum,woeMap);
    cateWgtWoeMap.put(columnNum,woeWgtMap);
    binPosRateMap.put(columnNum,posRateMap);
    numerMeanMap.put(columnNum,cs.getMean());
    numerStddevMap.put(columnNum,cs.getStddev());
    woeMeanMap.put(columnNum,cs.getWoeMean());
    woeStddevMap.put(columnNum,cs.getWoeStddev());
    wgtWoeMeanMap.put(columnNum,cs.getWoeWgtMean());
    wgtWoeStddevMap.put(columnNum,cs.getWoeWgtStddev());
    cutoffMap.put(columnNum,cs.getCutoff());
  }
  Map<Integer,Integer> columnMap=new HashMap<Integer,Integer>();
  int columnMapSize=dis.readInt();
  for (int i=0; i < columnMapSize; i++) {
    columnMap.put(dis.readInt(),dis.readInt());
  }
  BasicFloatNetwork network=new PersistBasicFloatNetwork().readNetwork(dis);
  return new IndependentNNModel(network,normType,numNameMap,cateColumnNameNames,columnMap,cateWoeMap,cateWgtWoeMap,binPosRateMap,numerBinBoundaries,numerWgtWoes,numerWoes,cutoffMap,numerMeanMap,numerStddevMap,woeMeanMap,woeStddevMap,wgtWoeMeanMap,wgtWoeStddevMap);
}