Program: 5442
Project: 5442
Buggy source:
/** 
 * Get the retry strategy for a program given its arguments and the CDAP defaults for the program type.
 * @return the retry strategy to use for internal calls
 * @throws IllegalArgumentException if there is an invalid value for an argument
 */
public static RetryStrategy getRetryStrategy(Map<String,String> args,ProgramType programType,CConfiguration cConf){
  String keyPrefix;
switch (programType) {
case MAPREDUCE:
    keyPrefix=Constants.Retry.MAPREDUCE_PREFIX;
  break;
case SPARK:
keyPrefix=Constants.Retry.SPARK_PREFIX;
break;
case WORKFLOW:
keyPrefix=Constants.Retry.WORKFLOW_PREFIX;
break;
case WORKER:
keyPrefix=Constants.Retry.WORKER_PREFIX;
break;
case SERVICE:
keyPrefix=Constants.Retry.SERVICE_PREFIX;
break;
case FLOW:
keyPrefix=Constants.Retry.FLOW_PREFIX;
break;
case CUSTOM_ACTION:
keyPrefix=Constants.Retry.CUSTOM_ACTION_PREFIX;
break;
default :
throw new IllegalArgumentException("String_Node_Str" + programType);
}
String typeKey=keyPrefix + Constants.Retry.TYPE;
String maxRetriesKey=keyPrefix + Constants.Retry.MAX_RETRIES;
String maxTimeKey=keyPrefix + Constants.Retry.MAX_TIME_SECS;
String baseDelayKey=keyPrefix + Constants.Retry.DELAY_BASE_MS;
String maxDelayKey=keyPrefix + Constants.Retry.DELAY_MAX_MS;
String typeStr=args.get(RETRY_POLICY_TYPE);
if (typeStr == null) {
typeStr=cConf.get(typeKey);
}
RetryStrategyType type=RetryStrategyType.from(typeStr);
if (type == RetryStrategyType.NONE) {
return RetryStrategies.noRetry();
}
int maxRetries=getNonNegativeInt(args,RETRY_POLICY_MAX_RETRIES,RETRY_POLICY_MAX_RETRIES,cConf.getInt(maxRetriesKey));
long maxTimeSecs=getNonNegativeLong(args,RETRY_POLICY_MAX_TIME_SECS,RETRY_POLICY_MAX_TIME_SECS,cConf.getLong(maxTimeKey));
long baseDelay=getNonNegativeLong(args,RETRY_POLICY_DELAY_BASE_MS,RETRY_POLICY_DELAY_BASE_MS,cConf.getLong(baseDelayKey));
RetryStrategy baseStrategy;
switch (type) {
case FIXED_DELAY:
baseStrategy=RetryStrategies.fixDelay(baseDelay,TimeUnit.MILLISECONDS);
break;
case EXPONENTIAL_BACKOFF:
long maxDelay=getNonNegativeLong(args,RETRY_POLICY_DELAY_MAX_MS,RETRY_POLICY_DELAY_MAX_MS,cConf.getLong(maxDelayKey));
baseStrategy=RetryStrategies.exponentialDelay(baseDelay,maxDelay,TimeUnit.MILLISECONDS);
break;
default :
throw new IllegalStateException("String_Node_Str" + type);
}
return RetryStrategies.limit(maxRetries,RetryStrategies.timeLimit(maxTimeSecs,TimeUnit.SECONDS,baseStrategy));
}

Fixed version (ground truth):
/** 
 * Get the retry strategy for a program given its arguments and the CDAP defaults for the program type.
 * @return the retry strategy to use for internal calls
 * @throws IllegalArgumentException if there is an invalid value for an argument
 */
public static RetryStrategy getRetryStrategy(Map<String,String> args,ProgramType programType,CConfiguration cConf){
  String keyPrefix;
switch (programType) {
case MAPREDUCE:
    keyPrefix=Constants.Retry.MAPREDUCE_PREFIX;
  break;
case SPARK:
keyPrefix=Constants.Retry.SPARK_PREFIX;
break;
case WORKFLOW:
keyPrefix=Constants.Retry.WORKFLOW_PREFIX;
break;
case WORKER:
keyPrefix=Constants.Retry.WORKER_PREFIX;
break;
case SERVICE:
keyPrefix=Constants.Retry.SERVICE_PREFIX;
break;
case FLOW:
keyPrefix=Constants.Retry.FLOW_PREFIX;
break;
case CUSTOM_ACTION:
keyPrefix=Constants.Retry.CUSTOM_ACTION_PREFIX;
break;
default :
throw new IllegalArgumentException("String_Node_Str" + programType);
}
CConfiguration policyConf=CConfiguration.copy(cConf);
String typeStr=args.get(RETRY_POLICY_TYPE);
if (typeStr != null) {
policyConf.set(keyPrefix + Constants.Retry.TYPE,typeStr);
}
int maxRetries=getNonNegativeInt(args,RETRY_POLICY_MAX_RETRIES,RETRY_POLICY_MAX_RETRIES,-1);
if (maxRetries >= 0) {
policyConf.setInt(keyPrefix + Constants.Retry.MAX_RETRIES,maxRetries);
}
long maxTimeSecs=getNonNegativeLong(args,RETRY_POLICY_MAX_TIME_SECS,RETRY_POLICY_MAX_TIME_SECS,-1L);
if (maxTimeSecs >= 0) {
policyConf.setLong(keyPrefix + Constants.Retry.MAX_TIME_SECS,maxTimeSecs);
}
long baseDelay=getNonNegativeLong(args,RETRY_POLICY_DELAY_BASE_MS,RETRY_POLICY_DELAY_BASE_MS,-1L);
if (baseDelay >= 0) {
policyConf.setLong(keyPrefix + Constants.Retry.DELAY_BASE_MS,baseDelay);
}
long maxDelay=getNonNegativeLong(args,RETRY_POLICY_DELAY_MAX_MS,RETRY_POLICY_DELAY_MAX_MS,-1L);
if (maxDelay >= 0) {
policyConf.setLong(keyPrefix + Constants.Retry.DELAY_MAX_MS,maxDelay);
}
return RetryStrategies.fromConfiguration(policyConf,keyPrefix);
}