Program: 31679
Project: 31679
Buggy source:
/** 
 * Load model instance from stream like model0.gbt or model0.rf. User can specify to use raw score or score after sigmoid transfrom by isConvertToProb.
 * @param input the input stream
 * @param isConvertToProb if convert score to probability (if to transform raw score by sigmoid)
 * @param isOptimizeMode if column index query is optimized
 * @param isRemoveNameSpace new column name including namespace like "a::b", if true, remove "a::" and set column name to simple name
 * @return the tree model instance
 * @throws IOException any exception in load input stream
 */
public static IndependentTreeModel loadFromStream(InputStream input,boolean isConvertToProb,boolean isOptimizeMode,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();
  IndependentTreeModel.setVersion(version);
  String algorithm=dis.readUTF();
  String lossStr=dis.readUTF();
  boolean isClassification=dis.readBoolean();
  boolean isOneVsAll=dis.readBoolean();
  int inputNode=dis.readInt();
  int size=dis.readInt();
  Map<Integer,Double> numericalMeanMapping=new HashMap<Integer,Double>(size,1f);
  Map<Integer,String> columnIndexNameMapping=new HashMap<Integer,String>(size,1f);
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    double mean=dis.readDouble();
    numericalMeanMapping.put(columnIndex,mean);
  }
  size=dis.readInt();
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    String columnName=dis.readUTF();
    if (isRemoveNameSpace) {
      columnName=CommonUtils.getSimpleColumnName(columnName);
    }
    columnIndexNameMapping.put(columnIndex,columnName);
  }
  size=dis.readInt();
  Map<Integer,List<String>> categoricalColumnNameNames=new HashMap<Integer,List<String>>(size,1f);
  Map<Integer,Map<String,Integer>> columnCategoryIndexMapping=new HashMap<Integer,Map<String,Integer>>(size,1f);
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    int categoryListSize=dis.readInt();
    Map<String,Integer> categoryIndexMapping=new HashMap<String,Integer>(categoryListSize,1f);
    List<String> categories=new ArrayList<String>(categoryListSize);
    for (int j=0; j < categoryListSize; j++) {
      String category=dis.readUTF();
      categories.add(category);
      if (category.contains(Constants.CATEGORICAL_GROUP_VAL_DELIMITER)) {
        String[] splits=split(category,Constants.CATEGORICAL_GROUP_VAL_DELIMITER);
        for (        String str : splits) {
          categoryIndexMapping.put(str,j);
          String tmStr=CommonUtils.trimTag(str);
          if (!str.equals(tmStr)) {
            categoryIndexMapping.put(tmStr,j);
          }
        }
      }
 else {
        categoryIndexMapping.put(category,j);
        String tmCategory=CommonUtils.trimTag(category);
        if (!category.equals(tmCategory)) {
          categoryIndexMapping.put(tmCategory,j);
        }
      }
    }
    categoricalColumnNameNames.put(columnIndex,categories);
    columnCategoryIndexMapping.put(columnIndex,categoryIndexMapping);
  }
  int columnMappingSize=dis.readInt();
  Map<Integer,Integer> columnMapping=new HashMap<Integer,Integer>(columnMappingSize,1f);
  for (int i=0; i < columnMappingSize; i++) {
    columnMapping.put(dis.readInt(),dis.readInt());
  }
  int treeNum=dis.readInt();
  List<TreeNode> trees=new CopyOnWriteArrayList<TreeNode>();
  List<Double> weights=new ArrayList<Double>(treeNum);
  for (int i=0; i < treeNum; i++) {
    TreeNode treeNode=new TreeNode();
    treeNode.readFields(dis);
    trees.add(treeNode);
    weights.add(treeNode.getLearningRate());
    if (isOptimizeMode) {
      treeNode.remapColumnNum(columnMapping);
    }
  }
  return new IndependentTreeModel(numericalMeanMapping,columnIndexNameMapping,categoricalColumnNameNames,columnCategoryIndexMapping,columnMapping,isOptimizeMode,trees,weights,CommonConstants.GBT_ALG_NAME.equalsIgnoreCase(algorithm),isClassification && !isOneVsAll,isConvertToProb,lossStr,algorithm,inputNode,version);
}

Fixed version (ground truth):
/** 
 * Load model instance from stream like model0.gbt or model0.rf. User can specify to use raw score or score after sigmoid transfrom by isConvertToProb.
 * @param input the input stream
 * @param isConvertToProb if convert score to probability (if to transform raw score by sigmoid)
 * @param isOptimizeMode if column index query is optimized
 * @param isRemoveNameSpace new column name including namespace like "a::b", if true, remove "a::" and set column name to simple name
 * @return the tree model instance
 * @throws IOException any exception in load input stream
 */
public static IndependentTreeModel loadFromStream(InputStream input,boolean isConvertToProb,boolean isOptimizeMode,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();
  IndependentTreeModel.setVersion(version);
  String algorithm=dis.readUTF();
  String lossStr=dis.readUTF();
  boolean isClassification=dis.readBoolean();
  boolean isOneVsAll=dis.readBoolean();
  int inputNode=dis.readInt();
  int size=dis.readInt();
  Map<Integer,Double> numericalMeanMapping=new HashMap<Integer,Double>(size,1f);
  Map<Integer,String> columnIndexNameMapping=new HashMap<Integer,String>(size,1f);
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    double mean=dis.readDouble();
    numericalMeanMapping.put(columnIndex,mean);
  }
  size=dis.readInt();
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    String columnName=dis.readUTF();
    if (isRemoveNameSpace) {
      columnName=CommonUtils.getSimpleColumnName(columnName);
    }
    columnIndexNameMapping.put(columnIndex,columnName);
  }
  size=dis.readInt();
  Map<Integer,List<String>> categoricalColumnNameNames=new HashMap<Integer,List<String>>(size,1f);
  Map<Integer,Map<String,Integer>> columnCategoryIndexMapping=new HashMap<Integer,Map<String,Integer>>(size,1f);
  for (int i=0; i < size; i++) {
    int columnIndex=dis.readInt();
    int categoryListSize=dis.readInt();
    Map<String,Integer> categoryIndexMapping=new HashMap<String,Integer>(categoryListSize,1f);
    List<String> categories=new ArrayList<String>(categoryListSize);
    for (int j=0; j < categoryListSize; j++) {
      String category=dis.readUTF();
      categories.add(category);
      if (category.contains(Constants.CATEGORICAL_GROUP_VAL_DELIMITER)) {
        String[] splits=split(category,Constants.CATEGORICAL_GROUP_VAL_DELIMITER);
        for (        String str : splits) {
          categoryIndexMapping.put(str,j);
        }
      }
 else {
        categoryIndexMapping.put(category,j);
      }
    }
    categoricalColumnNameNames.put(columnIndex,categories);
    columnCategoryIndexMapping.put(columnIndex,categoryIndexMapping);
  }
  int columnMappingSize=dis.readInt();
  Map<Integer,Integer> columnMapping=new HashMap<Integer,Integer>(columnMappingSize,1f);
  for (int i=0; i < columnMappingSize; i++) {
    columnMapping.put(dis.readInt(),dis.readInt());
  }
  int treeNum=dis.readInt();
  List<TreeNode> trees=new CopyOnWriteArrayList<TreeNode>();
  List<Double> weights=new ArrayList<Double>(treeNum);
  for (int i=0; i < treeNum; i++) {
    TreeNode treeNode=new TreeNode();
    treeNode.readFields(dis);
    trees.add(treeNode);
    weights.add(treeNode.getLearningRate());
    if (isOptimizeMode) {
      treeNode.remapColumnNum(columnMapping);
    }
  }
  return new IndependentTreeModel(numericalMeanMapping,columnIndexNameMapping,categoricalColumnNameNames,columnCategoryIndexMapping,columnMapping,isOptimizeMode,trees,weights,CommonConstants.GBT_ALG_NAME.equalsIgnoreCase(algorithm),isClassification && !isOneVsAll,isConvertToProb,lossStr,algorithm,inputNode,version);
}