Program: 31738
Project: 31738
Buggy source:
@Override public void init(WorkerContext<DTMasterParams,DTWorkerParams> context){
  Properties props=context.getProps();
  try {
    SourceType sourceType=SourceType.valueOf(props.getProperty(CommonConstants.MODELSET_SOURCE_TYPE,SourceType.HDFS.toString()));
    this.modelConfig=CommonUtils.loadModelConfig(props.getProperty(CommonConstants.SHIFU_MODEL_CONFIG),sourceType);
    this.columnConfigList=CommonUtils.loadColumnConfigList(props.getProperty(CommonConstants.SHIFU_COLUMN_CONFIG),sourceType);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  this.columnCategoryIndexMapping=new HashMap<Integer,Map<String,Integer>>();
  for (  ColumnConfig config : this.columnConfigList) {
    if (config.isCategorical()) {
      if (config.getBinCategory() != null) {
        Map<String,Integer> tmpMap=new HashMap<String,Integer>();
        for (int i=0; i < config.getBinCategory().size(); i++) {
          List<String> catVals=CommonUtils.flattenCatValGrp(config.getBinCategory().get(i));
          for (          String cval : catVals) {
            tmpMap.put(config.getBinCategory().get(i),i);
          }
        }
        this.columnCategoryIndexMapping.put(config.getColumnNum(),tmpMap);
      }
    }
  }
  Integer kCrossValidation=this.modelConfig.getTrain().getNumKFold();
  if (kCrossValidation != null && kCrossValidation > 0) {
    isKFoldCV=true;
  }
  Double upSampleWeight=modelConfig.getTrain().getUpSampleWeight();
  if (Double.compare(upSampleWeight,1d) != 0 && (modelConfig.isRegression() || (modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll()))) {
    LOG.info("String_Node_Str",upSampleWeight);
    this.upSampleRng=new PoissonDistribution(upSampleWeight - 1);
  }
  this.isContinuousEnabled=Boolean.TRUE.toString().equalsIgnoreCase(context.getProps().getProperty(CommonConstants.CONTINUOUS_TRAINING));
  this.workerThreadCount=modelConfig.getTrain().getWorkerThreadCount();
  this.threadPool=Executors.newFixedThreadPool(this.workerThreadCount);
  context.addCompletionCallBack(new WorkerCompletionCallBack<DTMasterParams,DTWorkerParams>(){
    @Override public void callback(    WorkerContext<DTMasterParams,DTWorkerParams> context){
      DTWorker.this.threadPool.shutdownNow();
      try {
        DTWorker.this.threadPool.awaitTermination(2,TimeUnit.SECONDS);
      }
 catch (      InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
);
  this.trainerId=Integer.valueOf(context.getProps().getProperty(CommonConstants.SHIFU_TRAINER_ID,"String_Node_Str"));
  this.isOneVsAll=modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll();
  GridSearch gs=new GridSearch(modelConfig.getTrain().getParams());
  Map<String,Object> validParams=this.modelConfig.getTrain().getParams();
  if (gs.hasHyperParam()) {
    validParams=gs.getParams(this.trainerId);
    LOG.info("String_Node_Str",validParams);
  }
  this.treeNum=Integer.valueOf(validParams.get("String_Node_Str").toString());
  double memoryFraction=Double.valueOf(context.getProps().getProperty("String_Node_Str","String_Node_Str"));
  LOG.info("String_Node_Str",Runtime.getRuntime().maxMemory(),memoryFraction);
  double validationRate=this.modelConfig.getValidSetRate();
  if (StringUtils.isNotBlank(modelConfig.getValidationDataSetRawPath())) {
    this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * 0.6),new ArrayList<Data>());
    this.validationData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * 0.4),new ArrayList<Data>());
  }
 else {
    if (Double.compare(validationRate,0d) != 0) {
      this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * (1 - validationRate)),new ArrayList<Data>());
      this.validationData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * validationRate),new ArrayList<Data>());
    }
 else {
      this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction),new ArrayList<Data>());
    }
  }
  int[] inputOutputIndex=DTrainUtils.getNumericAndCategoricalInputAndOutputCounts(this.columnConfigList);
  this.inputCount=inputOutputIndex[0] + inputOutputIndex[1];
  this.isAfterVarSelect=(inputOutputIndex[3] == 1);
  this.isManualValidation=(modelConfig.getValidationDataSetRawPath() != null && !"String_Node_Str".equals(modelConfig.getValidationDataSetRawPath()));
  int numClasses=this.modelConfig.isClassification() ? this.modelConfig.getTags().size() : 2;
  String imStr=validParams.get("String_Node_Str").toString();
  int minInstancesPerNode=Integer.valueOf(validParams.get("String_Node_Str").toString());
  double minInfoGain=Double.valueOf(validParams.get("String_Node_Str").toString());
  if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new Entropy(numClasses,minInstancesPerNode,minInfoGain);
  }
 else   if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new Gini(numClasses,minInstancesPerNode,minInfoGain);
  }
 else   if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new FriedmanMSE(minInstancesPerNode,minInfoGain);
  }
 else {
    impurity=new Variance(minInstancesPerNode,minInfoGain);
  }
  this.isRF=ALGORITHM.RF.toString().equalsIgnoreCase(modelConfig.getAlgorithm());
  this.isGBDT=ALGORITHM.GBT.toString().equalsIgnoreCase(modelConfig.getAlgorithm());
  String lossStr=validParams.get("String_Node_Str").toString();
  if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new LogLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new AbsoluteLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new HalfGradSquaredLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new SquaredLoss();
  }
 else {
    try {
      this.loss=(Loss)ClassUtils.newInstance(Class.forName(lossStr));
    }
 catch (    ClassNotFoundException e) {
      LOG.warn("String_Node_Str",lossStr);
      this.loss=new SquaredLoss();
    }
  }
  if (this.isGBDT) {
    this.learningRate=Double.valueOf(validParams.get(CommonConstants.LEARNING_RATE).toString());
    Object swrObj=validParams.get("String_Node_Str");
    if (swrObj != null) {
      this.gbdtSampleWithReplacement=Boolean.TRUE.toString().equalsIgnoreCase(swrObj.toString());
    }
    Object dropoutObj=validParams.get(CommonConstants.DROPOUT_RATE);
    if (dropoutObj != null) {
      this.dropOutRate=Double.valueOf(dropoutObj.toString());
    }
  }
  this.isStratifiedSampling=this.modelConfig.getTrain().getStratifiedSample();
  this.checkpointOutput=new Path(context.getProps().getProperty(CommonConstants.SHIFU_DT_MASTER_CHECKPOINT_FOLDER,"String_Node_Str" + context.getAppId()));
  LOG.info("String_Node_Str",isAfterVarSelect,treeNum,impurity.getClass().getName(),loss.getClass().getName(),this.learningRate,this.gbdtSampleWithReplacement,this.isRF,this.isGBDT,this.isStratifiedSampling,this.isKFoldCV,kCrossValidation,this.dropOutRate);
  if (!context.isFirstIteration()) {
    if (this.isGBDT) {
      isNeedRecoverGBDTPredict=true;
    }
 else {
      recoverTrees=context.getLastMasterResult().getTrees();
    }
  }
  if (context.isFirstIteration() && this.isContinuousEnabled && this.isGBDT) {
    Path modelPath=new Path(context.getProps().getProperty(CommonConstants.GUAGUA_OUTPUT));
    TreeModel existingModel=null;
    try {
      existingModel=(TreeModel)CommonUtils.loadModel(modelConfig,modelPath,ShifuFileUtils.getFileSystemBySourceType(this.modelConfig.getDataSet().getSource()));
    }
 catch (    IOException e) {
      LOG.error("String_Node_Str",e);
    }
    if (existingModel == null) {
      LOG.warn("String_Node_Str");
      return;
    }
 else {
      recoverTrees=existingModel.getTrees();
      LOG.info("String_Node_Str",recoverTrees.size());
    }
  }
}

Fixed version (ground truth):
@Override public void init(WorkerContext<DTMasterParams,DTWorkerParams> context){
  Properties props=context.getProps();
  try {
    SourceType sourceType=SourceType.valueOf(props.getProperty(CommonConstants.MODELSET_SOURCE_TYPE,SourceType.HDFS.toString()));
    this.modelConfig=CommonUtils.loadModelConfig(props.getProperty(CommonConstants.SHIFU_MODEL_CONFIG),sourceType);
    this.columnConfigList=CommonUtils.loadColumnConfigList(props.getProperty(CommonConstants.SHIFU_COLUMN_CONFIG),sourceType);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  this.columnCategoryIndexMapping=new HashMap<Integer,Map<String,Integer>>();
  for (  ColumnConfig config : this.columnConfigList) {
    if (config.isCategorical()) {
      if (config.getBinCategory() != null) {
        Map<String,Integer> tmpMap=new HashMap<String,Integer>();
        for (int i=0; i < config.getBinCategory().size(); i++) {
          List<String> catVals=CommonUtils.flattenCatValGrp(config.getBinCategory().get(i));
          for (          String cval : catVals) {
            tmpMap.put(cval,i);
          }
        }
        this.columnCategoryIndexMapping.put(config.getColumnNum(),tmpMap);
      }
    }
  }
  Integer kCrossValidation=this.modelConfig.getTrain().getNumKFold();
  if (kCrossValidation != null && kCrossValidation > 0) {
    isKFoldCV=true;
  }
  Double upSampleWeight=modelConfig.getTrain().getUpSampleWeight();
  if (Double.compare(upSampleWeight,1d) != 0 && (modelConfig.isRegression() || (modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll()))) {
    LOG.info("String_Node_Str",upSampleWeight);
    this.upSampleRng=new PoissonDistribution(upSampleWeight - 1);
  }
  this.isContinuousEnabled=Boolean.TRUE.toString().equalsIgnoreCase(context.getProps().getProperty(CommonConstants.CONTINUOUS_TRAINING));
  this.workerThreadCount=modelConfig.getTrain().getWorkerThreadCount();
  this.threadPool=Executors.newFixedThreadPool(this.workerThreadCount);
  context.addCompletionCallBack(new WorkerCompletionCallBack<DTMasterParams,DTWorkerParams>(){
    @Override public void callback(    WorkerContext<DTMasterParams,DTWorkerParams> context){
      DTWorker.this.threadPool.shutdownNow();
      try {
        DTWorker.this.threadPool.awaitTermination(2,TimeUnit.SECONDS);
      }
 catch (      InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
);
  this.trainerId=Integer.valueOf(context.getProps().getProperty(CommonConstants.SHIFU_TRAINER_ID,"String_Node_Str"));
  this.isOneVsAll=modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll();
  GridSearch gs=new GridSearch(modelConfig.getTrain().getParams());
  Map<String,Object> validParams=this.modelConfig.getTrain().getParams();
  if (gs.hasHyperParam()) {
    validParams=gs.getParams(this.trainerId);
    LOG.info("String_Node_Str",validParams);
  }
  this.treeNum=Integer.valueOf(validParams.get("String_Node_Str").toString());
  double memoryFraction=Double.valueOf(context.getProps().getProperty("String_Node_Str","String_Node_Str"));
  LOG.info("String_Node_Str",Runtime.getRuntime().maxMemory(),memoryFraction);
  double validationRate=this.modelConfig.getValidSetRate();
  if (StringUtils.isNotBlank(modelConfig.getValidationDataSetRawPath())) {
    this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * 0.6),new ArrayList<Data>());
    this.validationData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * 0.4),new ArrayList<Data>());
  }
 else {
    if (Double.compare(validationRate,0d) != 0) {
      this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * (1 - validationRate)),new ArrayList<Data>());
      this.validationData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction * validationRate),new ArrayList<Data>());
    }
 else {
      this.trainingData=new MemoryLimitedList<Data>((long)(Runtime.getRuntime().maxMemory() * memoryFraction),new ArrayList<Data>());
    }
  }
  int[] inputOutputIndex=DTrainUtils.getNumericAndCategoricalInputAndOutputCounts(this.columnConfigList);
  this.inputCount=inputOutputIndex[0] + inputOutputIndex[1];
  this.isAfterVarSelect=(inputOutputIndex[3] == 1);
  this.isManualValidation=(modelConfig.getValidationDataSetRawPath() != null && !"String_Node_Str".equals(modelConfig.getValidationDataSetRawPath()));
  int numClasses=this.modelConfig.isClassification() ? this.modelConfig.getTags().size() : 2;
  String imStr=validParams.get("String_Node_Str").toString();
  int minInstancesPerNode=Integer.valueOf(validParams.get("String_Node_Str").toString());
  double minInfoGain=Double.valueOf(validParams.get("String_Node_Str").toString());
  if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new Entropy(numClasses,minInstancesPerNode,minInfoGain);
  }
 else   if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new Gini(numClasses,minInstancesPerNode,minInfoGain);
  }
 else   if (imStr.equalsIgnoreCase("String_Node_Str")) {
    impurity=new FriedmanMSE(minInstancesPerNode,minInfoGain);
  }
 else {
    impurity=new Variance(minInstancesPerNode,minInfoGain);
  }
  this.isRF=ALGORITHM.RF.toString().equalsIgnoreCase(modelConfig.getAlgorithm());
  this.isGBDT=ALGORITHM.GBT.toString().equalsIgnoreCase(modelConfig.getAlgorithm());
  String lossStr=validParams.get("String_Node_Str").toString();
  if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new LogLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new AbsoluteLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new HalfGradSquaredLoss();
  }
 else   if (lossStr.equalsIgnoreCase("String_Node_Str")) {
    this.loss=new SquaredLoss();
  }
 else {
    try {
      this.loss=(Loss)ClassUtils.newInstance(Class.forName(lossStr));
    }
 catch (    ClassNotFoundException e) {
      LOG.warn("String_Node_Str",lossStr);
      this.loss=new SquaredLoss();
    }
  }
  if (this.isGBDT) {
    this.learningRate=Double.valueOf(validParams.get(CommonConstants.LEARNING_RATE).toString());
    Object swrObj=validParams.get("String_Node_Str");
    if (swrObj != null) {
      this.gbdtSampleWithReplacement=Boolean.TRUE.toString().equalsIgnoreCase(swrObj.toString());
    }
    Object dropoutObj=validParams.get(CommonConstants.DROPOUT_RATE);
    if (dropoutObj != null) {
      this.dropOutRate=Double.valueOf(dropoutObj.toString());
    }
  }
  this.isStratifiedSampling=this.modelConfig.getTrain().getStratifiedSample();
  this.checkpointOutput=new Path(context.getProps().getProperty(CommonConstants.SHIFU_DT_MASTER_CHECKPOINT_FOLDER,"String_Node_Str" + context.getAppId()));
  LOG.info("String_Node_Str",isAfterVarSelect,treeNum,impurity.getClass().getName(),loss.getClass().getName(),this.learningRate,this.gbdtSampleWithReplacement,this.isRF,this.isGBDT,this.isStratifiedSampling,this.isKFoldCV,kCrossValidation,this.dropOutRate);
  if (!context.isFirstIteration()) {
    if (this.isGBDT) {
      isNeedRecoverGBDTPredict=true;
    }
 else {
      recoverTrees=context.getLastMasterResult().getTrees();
    }
  }
  if (context.isFirstIteration() && this.isContinuousEnabled && this.isGBDT) {
    Path modelPath=new Path(context.getProps().getProperty(CommonConstants.GUAGUA_OUTPUT));
    TreeModel existingModel=null;
    try {
      existingModel=(TreeModel)CommonUtils.loadModel(modelConfig,modelPath,ShifuFileUtils.getFileSystemBySourceType(this.modelConfig.getDataSet().getSource()));
    }
 catch (    IOException e) {
      LOG.error("String_Node_Str",e);
    }
    if (existingModel == null) {
      LOG.warn("String_Node_Str");
      return;
    }
 else {
      recoverTrees=existingModel.getTrees();
      LOG.info("String_Node_Str",recoverTrees.size());
    }
  }
}