nus-yam/ex-repair huggingface dataset:
Program: 26199
Project: 26199
Buggy source:
/** 
 * @param exchange
 */
public void mark(final Exchange exchange){
  long deltaInNanos=lastExchangeDelta();
  this.lastExchange=exchange;
  this.lastExchangeTime=System.nanoTime();
  this.exchangeRate.mark();
  updateAllIntervals(deltaInNanos);
}

Fixed version (ground truth):
/** 
 * @param exchange
 */
public void mark(final Exchange exchange){
  long deltaInNanos=lastExchangeDelta();
  this.lastExchange=exchange;
  this.lastExchangeTime=System.nanoTime();
  this.exchangeRate.mark();
  if (this.haveProcessedAtLeastOneExchange) {
    this.haveProcessedAtLeastOneExchange=true;
    updateAllIntervals(deltaInNanos);
  }
}
Program: 26200
Project: 26200
Buggy source:
@Override public void process(final Exchange exchange) throws Exception {
  LOGGER.debug(MARKER,"String_Node_Str",exchange);
  if (this.haveProcessedAtLeastOneExchange) {
    this.haveProcessedAtLeastOneExchange=true;
    Context internalContext=null;
    if (this.endpoint.isInternalTimerEnabled()) {
      Timer internalTimer=this.endpoint.getInternalTimer();
      if (internalTimer != null) {
        internalContext=internalTimer.time();
      }
    }
    try {
switch (this.endpoint.getTimingAction()) {
case START:
        startTimer(exchange);
case NOOP:
      this.endpoint.mark(exchange);
    addOptionalCounter(exchange);
  addOptionalHistogram(exchange);
break;
case STOP:
stopTimer(exchange);
break;
}
}
  finally {
if (internalContext != null) {
internalContext.stop();
}
}
}
}

Fixed version (ground truth):
@Override public void process(final Exchange exchange) throws Exception {
  LOGGER.debug(MARKER,"String_Node_Str",exchange);
  Context internalContext=null;
  if (this.endpoint.isInternalTimerEnabled()) {
    Timer internalTimer=this.endpoint.getInternalTimer();
    if (internalTimer != null) {
      internalContext=internalTimer.time();
    }
  }
  try {
switch (this.endpoint.getTimingAction()) {
case START:
      startTimer(exchange);
case NOOP:
    this.endpoint.mark(exchange);
  addOptionalCounter(exchange);
addOptionalHistogram(exchange);
break;
case STOP:
stopTimer(exchange);
break;
}
}
  finally {
if (internalContext != null) {
internalContext.stop();
}
}
}
Program: 26201
Project: 26201
Buggy source:
/** 
 */
public MetricsComponent(final ReporterDefinition... newReporterDefinitions){
  super(MetricsEndpoint.class);
  LOGGER.info(MARKER,"String_Node_Str",(Object[])newReporterDefinitions);
  for (  ReporterDefinition reporterDefinition : newReporterDefinitions) {
    String reporterDefinitionName=reporterDefinition.getName();
    if (reporterDefinitionName != null && this.reporterDefinitions.containsKey(reporterDefinitionName)) {
      throw new RuntimeCamelException("String_Node_Str" + reporterDefinitionName);
    }
    this.reporterDefinitions.put(reporterDefinitionName,reporterDefinition);
  }
}

Fixed version (ground truth):
/** 
 * @param newReporterDefinitions
 */
public MetricsComponent(final ReporterDefinition... newReporterDefinitions){
  super(MetricsEndpoint.class);
  LOGGER.info(MARKER,"String_Node_Str",(Object[])newReporterDefinitions);
  for (  ReporterDefinition reporterDefinition : newReporterDefinitions) {
    String reporterDefinitionName=reporterDefinition.getName();
    if (reporterDefinitionName != null && this.reporterDefinitions.containsKey(reporterDefinitionName)) {
      throw new RuntimeCamelException("String_Node_Str" + reporterDefinitionName);
    }
    this.reporterDefinitions.put(reporterDefinitionName,reporterDefinition);
  }
}
Program: 26202
Project: 26202
Buggy source:
/** 
 * @param uri
 * @param metricsComponent
 * @param name
 * @param parameters
 * @throws Exception
 */
public MetricsEndpoint(final String uri,final MetricsComponent metricsComponent,final String name,final Map<String,Object> parameters) throws Exception {
  super(uri,metricsComponent);
  LOGGER.debug(MARKER,"String_Node_Str",uri,metricsComponent,parameters);
  this.metricsComponent=metricsComponent;
  this.name=name;
  this.metricsComponent.registerName(this.name);
  this.metricRegistry=new MetricRegistry();
  LoggingMetricRegistryListener listener=new LoggingMetricRegistryListener(LOGGER,MARKER,LoggingMetricRegistryListener.Level.INFO);
  this.metricRegistry.addListener(listener);
  warnIfTimingStopIsUsedWithOtherParameters(parameters);
  EndpointHelper.setProperties(getCamelContext(),this,parameters);
switch (this.timingAction) {
case STOP:
    LOGGER.debug(MARKER,"String_Node_Str",this.timingAction);
  break;
default :
initializeMetrics();
break;
}
}

Fixed version (ground truth):
/** 
 * @param uri
 * @param metricsComponent
 * @param name
 * @param parameters
 * @throws Exception
 */
public MetricsEndpoint(final String uri,final MetricsComponent metricsComponent,final String name,final Map<String,Object> parameters) throws Exception {
  super(uri,metricsComponent);
  LOGGER.debug(MARKER,"String_Node_Str",uri,metricsComponent,parameters);
  this.metricsComponent=metricsComponent;
  this.name=name;
  this.metricRegistry=new MetricRegistry();
  LoggingMetricRegistryListener listener=new LoggingMetricRegistryListener(LOGGER,MARKER,LoggingMetricRegistryListener.Level.INFO);
  this.metricRegistry.addListener(listener);
  warnIfTimingStopIsUsedWithOtherParameters(parameters);
  EndpointHelper.setProperties(getCamelContext(),this,parameters);
switch (this.timingAction) {
case STOP:
    LOGGER.debug(MARKER,"String_Node_Str",this.timingAction);
  break;
default :
this.metricsComponent.registerName(this.name);
initializeMetrics();
break;
}
}
Program: 26203
Project: 26203
Buggy source:
/** 
 * @param value
 * @param type
 * @return
 */
public static <T>T parse(final String value,final Class<T> type){
  if (Boolean.class.isAssignableFrom(type)) {
    type.cast(parseBoolean(value));
  }
 else   if (TimeUnit.class.isAssignableFrom(type)) {
    type.cast(parseTimeUnit(value));
  }
  return null;
}

Fixed version (ground truth):
/** 
 * @param value
 * @param type
 * @return
 */
public static <T>T parse(final String value,final Class<T> type){
  if (Boolean.class.isAssignableFrom(type)) {
    return type.cast(parseBoolean(value));
  }
 else   if (TimeUnit.class.isAssignableFrom(type)) {
    return type.cast(parseTimeUnit(value));
  }
  return null;
}
Program: 26204
Project: 26204
Buggy source:
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setActionBarContentView(R.layout.insight_vote);
  SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
  accessToken=prefs.getString("String_Node_Str",null);
  userName=prefs.getString("String_Node_Str",null);
  insightList=new ArrayList<InsightListItem>();
  cxt=this;
  radioGroup=(RadioGroup)findViewById(R.id.agreeDisagreeButtons);
  radioAgree=(RadioButton)findViewById(R.id.buttonAgree);
  radioAgree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      agree();
    }
  }
);
  radioDisagree=(RadioButton)findViewById(R.id.buttonDisagree);
  radioDisagree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      disagree();
    }
  }
);
  pager=(ViewPager)findViewById(R.id.insightPager);
  pager.setAdapter(new InsightListPagerAdapter());
  pager.setOnPageChangeListener(new MyPageChangeListener());
  if (accessToken == null) {
    openConnectScreen();
    return;
  }
  final ActivityData data=(ActivityData)getLastNonConfigurationInstance();
  if (data != null) {
    insightList=data.insightList;
    currentInsightIndex=data.currentInsightIndex;
  }
 else {
    String alertTitle="String_Node_Str";
    if (userName != null) {
      alertTitle=userName;
    }
    loadingInsightsDialog=ProgressDialog.show(this,alertTitle,getResources().getText(R.string.loading_insights),true);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    fetchNextInsights();
  }
}

Fixed version (ground truth):
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setActionBarContentView(R.layout.insight_vote);
  SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
  accessToken=prefs.getString("String_Node_Str",null);
  userName=prefs.getString("String_Node_Str",null);
  insightList=new ArrayList<InsightListItem>();
  cxt=this;
  radioGroup=(RadioGroup)findViewById(R.id.agreeDisagreeButtons);
  radioAgree=(RadioButton)findViewById(R.id.buttonAgree);
  radioAgree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      agree();
    }
  }
);
  radioDisagree=(RadioButton)findViewById(R.id.buttonDisagree);
  radioDisagree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      disagree();
    }
  }
);
  pager=(ViewPager)findViewById(R.id.insightPager);
  pager.setAdapter(new InsightListPagerAdapter());
  pager.setOnPageChangeListener(new MyPageChangeListener());
  if (accessToken == null) {
    openConnectScreen();
    return;
  }
  final ActivityData data=(ActivityData)getLastNonConfigurationInstance();
  if (data != null) {
    insightList=data.insightList;
    currentInsightIndex=data.currentInsightIndex;
  }
 else {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    showDialog(DIALOG_LOADING_INSIGHTS_ID);
    fetchNextInsights();
  }
}
Program: 26205
Project: 26205
Buggy source:
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setActionBarContentView(R.layout.insight_vote);
  SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
  accessToken=prefs.getString("String_Node_Str",null);
  userName=prefs.getString("String_Node_Str",null);
  insightList=new ArrayList<InsightListItem>();
  cxt=this;
  radioGroup=(RadioGroup)findViewById(R.id.agreeDisagreeButtons);
  radioAgree=(RadioButton)findViewById(R.id.buttonAgree);
  radioAgree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      agree();
    }
  }
);
  radioDisagree=(RadioButton)findViewById(R.id.buttonDisagree);
  radioDisagree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      disagree();
    }
  }
);
  pager=(ViewPager)findViewById(R.id.insightPager);
  pager.setAdapter(new InsightListPagerAdapter());
  pager.setOnPageChangeListener(new MyPageChangeListener());
  if (accessToken == null) {
    openConnectScreen();
    return;
  }
  final ActivityData data=(ActivityData)getLastNonConfigurationInstance();
  if (data != null) {
    insightList=data.insightList;
    currentInsightIndex=data.currentInsightIndex;
  }
 else {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    showDialog(DIALOG_LOADING_INSIGHTS_ID);
    fetchNextInsights();
  }
}

Fixed version (ground truth):
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setActionBarContentView(R.layout.insight_vote);
  SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
  accessToken=prefs.getString("String_Node_Str",null);
  userName=prefs.getString("String_Node_Str",null);
  insightList=new ArrayList<InsightListItem>();
  cxt=this;
  radioGroup=(RadioGroup)findViewById(R.id.agreeDisagreeButtons);
  radioAgree=(RadioButton)findViewById(R.id.buttonAgree);
  radioAgree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      agree();
    }
  }
);
  radioDisagree=(RadioButton)findViewById(R.id.buttonDisagree);
  radioDisagree.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      disagree();
    }
  }
);
  pager=(ViewPager)findViewById(R.id.insightPager);
  pager.setAdapter(new InsightListPagerAdapter());
  pager.setOnPageChangeListener(new MyPageChangeListener());
  if (accessToken == null) {
    openConnectScreen();
    return;
  }
  final ActivityData data=(ActivityData)getLastNonConfigurationInstance();
  if (data != null) {
    insightList=data.insightList;
    currentInsightIndex=data.currentInsightIndex;
  }
  if (insightList.isEmpty()) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    showDialog(DIALOG_LOADING_INSIGHTS_ID);
    fetchNextInsights();
  }
}
Program: 26207
Project: 26207
Buggy source:
public void onPageStarted(WebView view,String url,Bitmap favicon){
  Log.v("String_Node_Str","String_Node_Str" + url + "String_Node_Str");
  int start=url.indexOf(FRAGMENT);
  if (start > -1) {
    String accessToken=url.substring(start + FRAGMENT.length(),url.length());
    Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
    SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
    Editor editor=prefs.edit();
    editor.putString("String_Node_Str",accessToken);
    editor.commit();
    Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
    startActivity(homeActivity);
  }
}

Fixed version (ground truth):
public void onPageStarted(WebView view,String url,Bitmap favicon){
  int start=url.indexOf(FRAGMENT);
  if (start > -1) {
    String accessToken=url.substring(start + FRAGMENT.length(),url.length());
    Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
    SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
    Editor editor=prefs.edit();
    editor.putString("String_Node_Str",accessToken);
    editor.commit();
    Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
    startActivity(homeActivity);
  }
}
Program: 26208
Project: 26208
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_webview);
  String url=BeansightApi.DOMAIN + "String_Node_Str";
  WebView webView=(WebView)findViewById(R.id.webkitWebView);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient(){
    public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      Log.v("String_Node_Str","String_Node_Str" + url + "String_Node_Str");
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        String accessToken=url.substring(start + FRAGMENT.length(),url.length());
        Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
        SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
        Editor editor=prefs.edit();
        editor.putString("String_Node_Str",accessToken);
        editor.commit();
        Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
        startActivity(homeActivity);
      }
    }
    public void onPageFinished(    WebView view,    String url){
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        CookieManager.getInstance().removeAllCookie();
        Log.v("String_Node_Str","String_Node_Str");
      }
    }
  }
);
  webView.loadUrl(url);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_webview);
  String url=BeansightApi.DOMAIN + "String_Node_Str";
  WebView webView=(WebView)findViewById(R.id.webkitWebView);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient(){
    public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        String accessToken=url.substring(start + FRAGMENT.length(),url.length());
        Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
        SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
        Editor editor=prefs.edit();
        editor.putString("String_Node_Str",accessToken);
        editor.commit();
        Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
        startActivity(homeActivity);
      }
    }
    public void onPageFinished(    WebView view,    String url){
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        CookieManager.getInstance().removeAllCookie();
        Log.v("String_Node_Str","String_Node_Str");
      }
    }
  }
);
  webView.loadUrl(url);
}
Program: 26209
Project: 26209
Buggy source:
public static InsightDetailResponse show(String accessToken,String id) throws NotAuthenticatedException, IOException, ServerErrorException {
  Log.v("String_Node_Str",String.format("String_Node_Str",accessToken,id));
  InsightDetailResponse insightDetailResponse=null;
  String result=generateRequest("String_Node_Str",accessToken).data("String_Node_Str",id).asString();
  Gson gson=new Gson();
  try {
    insightDetailResponse=gson.fromJson(result,InsightDetailResponse.class);
  }
 catch (  JsonSyntaxException e) {
    throw new ServerErrorException(e);
  }
  return insightDetailResponse;
}

Fixed version (ground truth):
public static InsightDetailResponse show(String accessToken,String id) throws NotAuthenticatedException, IOException, ServerErrorException {
  InsightDetailResponse insightDetailResponse=null;
  String result=generateRequest("String_Node_Str",accessToken).data("String_Node_Str",id).asString();
  Gson gson=new Gson();
  try {
    insightDetailResponse=gson.fromJson(result,InsightDetailResponse.class);
  }
 catch (  JsonSyntaxException e) {
    throw new ServerErrorException(e);
  }
  return insightDetailResponse;
}
Program: 26210
Project: 26210
Buggy source:
private static HttpRequestBuilder generateRequest(String apiAction,String accessToken){
  String url=String.format("String_Node_Str" + apiAction,DOMAIN);
  return Http.get(url).use(client).data("String_Node_Str",accessToken);
}

Fixed version (ground truth):
private static HttpRequestBuilder generateRequest(String apiAction,String accessToken){
  HttpClient client=new DefaultHttpClient();
  String url=String.format("String_Node_Str" + apiAction,DOMAIN);
  return Http.get(url).use(client).data("String_Node_Str",accessToken);
}
Program: 26211
Project: 26211
Buggy source:
public void onPageStarted(WebView view,String url,Bitmap favicon){
  String fragment="String_Node_Str";
  int start=url.indexOf(fragment);
  if (start > -1) {
    String accessToken=url.substring(start + fragment.length(),url.length());
    Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
    SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
    Editor editor=prefs.edit();
    editor.putString("String_Node_Str",accessToken);
    editor.commit();
    Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
    startActivity(homeActivity);
  }
}

Fixed version (ground truth):
public void onPageStarted(WebView view,String url,Bitmap favicon){
  Log.v("String_Node_Str","String_Node_Str" + url + "String_Node_Str");
  int start=url.indexOf(FRAGMENT);
  if (start > -1) {
    String accessToken=url.substring(start + FRAGMENT.length(),url.length());
    Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
    SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
    Editor editor=prefs.edit();
    editor.putString("String_Node_Str",accessToken);
    editor.commit();
    Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
    startActivity(homeActivity);
  }
}
Program: 26212
Project: 26212
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_webview);
  String url=BeansightApi.domain + "String_Node_Str";
  WebView webView=(WebView)findViewById(R.id.webkitWebView);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient(){
    public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      String fragment="String_Node_Str";
      int start=url.indexOf(fragment);
      if (start > -1) {
        String accessToken=url.substring(start + fragment.length(),url.length());
        Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
        SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
        Editor editor=prefs.edit();
        editor.putString("String_Node_Str",accessToken);
        editor.commit();
        Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
        startActivity(homeActivity);
      }
    }
  }
);
  webView.loadUrl(url);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_webview);
  String url=BeansightApi.DOMAIN + "String_Node_Str";
  WebView webView=(WebView)findViewById(R.id.webkitWebView);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient(){
    public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      Log.v("String_Node_Str","String_Node_Str" + url + "String_Node_Str");
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        String accessToken=url.substring(start + FRAGMENT.length(),url.length());
        Log.v("String_Node_Str","String_Node_Str" + accessToken + "String_Node_Str");
        SharedPreferences prefs=getSharedPreferences(BeansightApplication.BEANSIGHT_PREFS,0);
        Editor editor=prefs.edit();
        editor.putString("String_Node_Str",accessToken);
        editor.commit();
        Intent homeActivity=new Intent(WebViewActivity.this,HomeActivity.class);
        startActivity(homeActivity);
      }
    }
    public void onPageFinished(    WebView view,    String url){
      int start=url.indexOf(FRAGMENT);
      if (start > -1) {
        CookieManager.getInstance().removeAllCookie();
        Log.v("String_Node_Str","String_Node_Str");
      }
    }
  }
);
  webView.loadUrl(url);
}
Program: 26213
Project: 26213
Buggy source:
private static HttpRequestBuilder generateRequest(String apiAction,String accessToken){
  String url=String.format("String_Node_Str" + apiAction,domain);
  return Http.get(url).use(client).data("String_Node_Str",accessToken);
}

Fixed version (ground truth):
private static HttpRequestBuilder generateRequest(String apiAction,String accessToken){
  String url=String.format("String_Node_Str" + apiAction,DOMAIN);
  return Http.get(url).use(client).data("String_Node_Str",accessToken);
}
Program: 26214
Project: 26214
Buggy source:
public void reduce(TextPairWC termFile,Iterable<TermInfo> termInfos,Context context) throws IOException, InterruptedException {
  TermInfo[] termInfos_Array=Iterables.toArray(termInfos,TermInfo.class);
  IntWritable df=new IntWritable(termInfos_Array.length);
  context.write(new TextIntWC(termFile.getFirst(),df),new TermInfoArray(termInfos_Array));
}

Fixed version (ground truth):
public void reduce(TextPairWC termFile,Iterable<TermInfo> termInfos,Context context) throws IOException, InterruptedException {
  ArrayList<TermInfo> termInfos_lst=new ArrayList<TermInfo>();
  for (  TermInfo termInfo : termInfos)   termInfos_lst.add((TermInfo)WritableUtils.clone(termInfo,context.getConfiguration()));
  TermInfo[] termInfos_Array=termInfos_lst.toArray(new TermInfo[termInfos_lst.size()]);
  IntWritable df=new IntWritable(termInfos_Array.length);
  context.write(new TextIntWC(termFile.getFirst(),df),new TermInfoArray(termInfos_Array));
}
Program: 26215
Project: 26215
Buggy source:
/** 
 * Compare an elastic and a raw transform loaded from file. The result is expressed using the warping index and displayed in the Log window.
 * @param elasticTransfPath complete path to elastic transform file
 * @param rawTransfPath complete path to raw transform file
 */
public static void compareElasticRawTransforms(final String elasticTransfPath,final String rawTransfPath){
  final MainDialog md=bUnwarpJ_.getMainDialog();
  if (null == md) {
    IJ.log("String_Node_Str");
    return;
  }
  int intervals=MiscTools.numberOfIntervalsOfTransformation(elasticTransfPath);
  double[][] cx=new double[intervals + 3][intervals + 3];
  double[][] cy=new double[intervals + 3][intervals + 3];
  MiscTools.loadTransformation(elasticTransfPath,cx,cy);
  final double[][] transformation_x=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  final double[][] transformation_y=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  MiscTools.loadRawTransformation(rawTransfPath,transformation_x,transformation_y);
  double warpingIndex=MiscTools.warpingIndex(md.getSourceImp(),md.getTargetImp(),intervals,cx,cy,transformation_x,transformation_y);
  if (warpingIndex != -1)   IJ.log("String_Node_Str" + warpingIndex);
 else   IJ.log("String_Node_Str" + "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Compare an elastic and a raw transform loaded from file. The result is expressed using the warping index and displayed in the Log window.
 * @param elasticTransfPath complete path to elastic transform file
 * @param rawTransfPath complete path to raw transform file
 */
public static void compareElasticRawTransforms(final String elasticTransfPath,final String rawTransfPath){
  final MainDialog md=bUnwarpJ_.getMainDialog();
  if (null == md) {
    IJ.log("String_Node_Str");
    return;
  }
  int intervals=MiscTools.numberOfIntervalsOfTransformation(elasticTransfPath);
  double[][] cx=new double[intervals + 3][intervals + 3];
  double[][] cy=new double[intervals + 3][intervals + 3];
  MiscTools.loadTransformation(elasticTransfPath,cx,cy);
  final double[][] transformation_x=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  final double[][] transformation_y=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  MiscTools.loadRawTransformation(rawTransfPath,transformation_x,transformation_y);
  double warpingIndex=MiscTools.rawWarpingIndex(md.getSourceImp(),md.getTargetImp(),intervals,cx,cy,transformation_x,transformation_y);
  if (warpingIndex != -1)   IJ.log("String_Node_Str" + warpingIndex);
 else   IJ.log("String_Node_Str" + "String_Node_Str");
}
Program: 26220
Project: 26220
Buggy source:
/** 
 * Convert an elastic transform to raw format and save it to file.
 * @param rawTransfPath complete path to input raw transform file
 * @param elasticTransfPath complete path to output elastic transform file
 * @param intervals number of intervals in the B-spline grid
 */
public static void convertToElastic(final String rawTransfPath,final String elasticTransfPath,final String strIntervals){
  final MainDialog md=bUnwarpJ_.getMainDialog();
  if (null == md) {
    IJ.log("String_Node_Str");
    return;
  }
  final int intervals=Integer.parseInt(strIntervals);
  final double[][] transformation_x=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  final double[][] transformation_y=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  MiscTools.loadRawTransformation(rawTransfPath,transformation_x,transformation_y);
  double[][] cx=new double[intervals + 3][intervals + 3];
  double[][] cy=new double[intervals + 3][intervals + 3];
  MiscTools.convertRawTransformationToBSpline(md.getTargetImp(),intervals,transformation_x,transformation_y,cx,cy);
  MiscTools.saveElasticTransformation(intervals,cx,cy,elasticTransfPath);
}

Fixed version (ground truth):
/** 
 * Convert an elastic transform to raw format and save it to file.
 * @param rawTransfPath complete path to input raw transform file
 * @param elasticTransfPath complete path to output elastic transform file
 * @param strIntervals number of intervals in the B-spline grid
 */
public static void convertToElastic(final String rawTransfPath,final String elasticTransfPath,final String strIntervals){
  final MainDialog md=bUnwarpJ_.getMainDialog();
  if (null == md) {
    IJ.log("String_Node_Str");
    return;
  }
  final int intervals=Integer.parseInt(strIntervals);
  final double[][] transformation_x=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  final double[][] transformation_y=new double[md.getTarget().getHeight()][md.getTarget().getWidth()];
  MiscTools.loadRawTransformation(rawTransfPath,transformation_x,transformation_y);
  double[][] cx=new double[intervals + 3][intervals + 3];
  double[][] cy=new double[intervals + 3][intervals + 3];
  MiscTools.convertRawTransformationToBSpline(md.getTargetImp(),intervals,transformation_x,transformation_y,cx,cy);
  MiscTools.saveElasticTransformation(intervals,cx,cy,elasticTransfPath);
}
Program: 26231
Project: 26231
Buggy source:
/** 
 * Start the image precomputations. The computation of the B-spline coefficients of the full-size image is not interruptible; all other methods are.
 */
public void run(){
  if (image == null && ip != null) {
    image=new double[width * height];
    MiscTools.extractImage(ip,image);
  }
  coefficient=getBasicFromCardinal2D();
  buildCoefficientPyramid();
  if (isTarget || this.bSubsampledOutput)   buildImagePyramid();
}

Fixed version (ground truth):
/** 
 * Start the image pre-computations. The computation of the B-spline coefficients of the full-size image is not interruptible; all other methods are.
 */
public void run(){
  if (image == null && ip != null) {
    this.original_image=new double[width * height];
    this.originalHeight=this.height;
    this.originalWidth=this.width;
    MiscTools.extractImage(ip,this.original_image);
    if (this.maxImageSubsamplingFactor != 0) {
      final float scaleFactor=(float)(1.0f / this.maxImageSubsamplingFactor);
      this.ip=MiscTools.scale(ip,scaleFactor);
      this.width=ip.getWidth();
      this.height=ip.getHeight();
    }
    this.image=new double[width * height];
    MiscTools.extractImage(ip,this.image);
    if (this.width <= this.subWidth) {
      this.subWidth=this.width;
      this.subHeight=this.height;
      this.subImage=this.image;
    }
  }
  coefficient=getBasicFromCardinal2D();
  buildCoefficientPyramid();
  if (isTarget || this.bSubsampledOutput)   buildImagePyramid();
}
Program: 26234
Project: 26234
Buggy source:
/** 
 * @param c
 * @param width
 * @param height
 */
public double[] reduceCoeffsBy2(double[] c,int width,int height){
  double[] fullDual=new double[width * height];
  int halfWidth=width / 2;
  int halfHeight=height / 2;
  basicToCardinal2D(c,fullDual,width,height,7);
  final double[] halfDual=getHalfDual2D(fullDual,width,height);
  final double[] halfCoefficient=getBasicFromCardinal2D(halfDual,halfWidth,halfHeight,7);
  return halfCoefficient;
}

Fixed version (ground truth):
/** 
 * Reduce coefficients by a factor of 2 (beta)
 * @param c
 * @param width
 * @param height
 */
public double[] reduceCoeffsBy2(double[] c,int width,int height){
  double[] fullDual=new double[width * height];
  int halfWidth=width / 2;
  int halfHeight=height / 2;
  basicToCardinal2D(c,fullDual,width,height,7);
  final double[] halfDual=getHalfDual2D(fullDual,width,height);
  final double[] halfCoefficient=getBasicFromCardinal2D(halfDual,halfWidth,halfHeight,7);
  return halfCoefficient;
}
Program: 26235
Project: 26235
Buggy source:
/** 
 * Get image.
 * @return the full-size image.
 */
public double[] getImage(){
  return image;
}

Fixed version (ground truth):
/** 
 * Get image (at the maximum resolution size determined by the scaling).
 * @return the less scaled image.
 */
public double[] getImage(){
  return image;
}
Program: 26237
Project: 26237
Buggy source:
/** 
 * Create target image.
 */
private void createTargetImage(){
  if (this.bMacro) {
    String macroOptions=Macro.getOptions();
    Choice thisChoice=this.targetChoice;
    String item=thisChoice.getSelectedItem();
    item=Macro.getValue(macroOptions,"String_Node_Str",item);
    for (int i=0; i < this.imageList.length; i++)     if ((this.imageList[i].getTitle()).equals(item)) {
      this.targetChoiceIndex=i;
      break;
    }
  }
  targetImp=imageList[targetChoiceIndex];
  if (this.targetImp.getStackSize() > 1)   this.originalTargetIP=this.targetImp.getStack().getProcessor(1);
 else   this.originalTargetIP=this.targetImp.getProcessor();
  target=new BSplineModel(targetImp.getProcessor(),true,(int)Math.pow(2,this.maxImageSubsamplingFactor));
  this.computeImagePyramidDepth();
  target.setPyramidDepth(imagePyramidDepth + min_scale_image);
  targetIc=targetImp.getWindow().getCanvas();
  if (targetImp.getStackSize() == 1) {
    targetMsk=new Mask(targetImp.getProcessor(),false);
  }
 else {
    targetMsk=new Mask(targetImp.getStack().getProcessor(2),true);
  }
  targetPh=new PointHandler(targetImp,tb,targetMsk,this);
  tb.setTarget(targetImp,targetPh);
}

Fixed version (ground truth):
/** 
 * Create target image.
 */
private void createTargetImage(){
  if (this.bMacro) {
    String macroOptions=Macro.getOptions();
    Choice thisChoice=this.targetChoice;
    String item=thisChoice.getSelectedItem();
    item=Macro.getValue(macroOptions,"String_Node_Str",item);
    for (int i=0; i < this.imageList.length; i++)     if ((this.imageList[i].getTitle()).equals(item)) {
      this.targetChoiceIndex=i;
      break;
    }
  }
  targetImp=imageList[targetChoiceIndex];
  if (this.targetImp.getStackSize() > 1)   this.originalTargetIP=this.targetImp.getStack().getProcessor(1);
 else   this.originalTargetIP=this.targetImp.getProcessor();
  this.target=new BSplineModel(targetImp.getProcessor(),true,(int)Math.pow(2,this.maxImageSubsamplingFactor));
  this.computeImagePyramidDepth();
  this.target.setPyramidDepth(imagePyramidDepth + min_scale_image);
  this.targetIc=targetImp.getWindow().getCanvas();
  if (targetImp.getStackSize() == 1) {
    this.targetMsk=new Mask(targetImp.getProcessor(),false);
  }
 else {
    this.targetMsk=new Mask(targetImp.getStack().getProcessor(2),true);
  }
  this.targetPh=new PointHandler(targetImp,tb,targetMsk,this);
  this.tb.setTarget(targetImp,targetPh);
}
Program: 26239
Project: 26239
Buggy source:
/** 
 * Create the source image.
 * @param bIsReverse determines the transformation direction (source-target=TRUE or target-source=FALSE)
 */
private void createSourceImage(boolean bIsReverse){
  if (this.bMacro) {
    String macroOptions=Macro.getOptions();
    Choice thisChoice=this.sourceChoice;
    String item=thisChoice.getSelectedItem();
    item=Macro.getValue(macroOptions,"String_Node_Str",item);
    for (int i=0; i < this.imageList.length; i++)     if ((this.imageList[i].getTitle()).equals(item)) {
      this.sourceChoiceIndex=i;
      break;
    }
  }
  sourceImp=imageList[sourceChoiceIndex];
  if (this.sourceImp.getStackSize() > 1)   this.originalSourceIP=this.sourceImp.getStack().getProcessor(1);
 else   this.originalSourceIP=this.sourceImp.getProcessor();
  source=new BSplineModel(sourceImp.getProcessor(),bIsReverse,(int)Math.pow(2,this.maxImageSubsamplingFactor));
  this.computeImagePyramidDepth();
  source.setPyramidDepth(imagePyramidDepth + min_scale_image);
  sourceIc=sourceImp.getWindow().getCanvas();
  if (sourceImp.getStackSize() == 1) {
    sourceMsk=new Mask(sourceImp.getProcessor(),false);
  }
 else {
    sourceMsk=new Mask(sourceImp.getStack().getProcessor(2),true);
  }
  sourcePh=new PointHandler(sourceImp,tb,sourceMsk,this);
  tb.setSource(sourceImp,sourcePh);
}

Fixed version (ground truth):
/** 
 * Create the source image, i.e. initialize the B-spline model for the source image. The resolution pyramid is not started here, but in startPyramids. 
 * @param bIsReverse determines the transformation direction (source-target=TRUE or target-source=FALSE)
 */
private void createSourceImage(boolean bIsReverse){
  if (this.bMacro) {
    String macroOptions=Macro.getOptions();
    Choice thisChoice=this.sourceChoice;
    String item=thisChoice.getSelectedItem();
    item=Macro.getValue(macroOptions,"String_Node_Str",item);
    for (int i=0; i < this.imageList.length; i++)     if ((this.imageList[i].getTitle()).equals(item)) {
      this.sourceChoiceIndex=i;
      break;
    }
  }
  sourceImp=imageList[sourceChoiceIndex];
  if (this.sourceImp.getStackSize() > 1)   this.originalSourceIP=this.sourceImp.getStack().getProcessor(1);
 else   this.originalSourceIP=this.sourceImp.getProcessor();
  source=new BSplineModel(sourceImp.getProcessor(),bIsReverse,(int)Math.pow(2,this.maxImageSubsamplingFactor));
  this.computeImagePyramidDepth();
  source.setPyramidDepth(imagePyramidDepth + min_scale_image);
  sourceIc=sourceImp.getWindow().getCanvas();
  if (sourceImp.getStackSize() == 1) {
    sourceMsk=new Mask(sourceImp.getProcessor(),false);
  }
 else {
    sourceMsk=new Mask(sourceImp.getStack().getProcessor(2),true);
  }
  sourcePh=new PointHandler(sourceImp,tb,sourceMsk,this);
  tb.setSource(sourceImp,sourcePh);
}
Program: 26240
Project: 26240
Buggy source:
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent){
  MainDialog.this.maxImageSubsamplingFactor=Integer.parseInt(resamplingTextField.getText());
}

Fixed version (ground truth):
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent){
  MainDialog.this.maxImageSubsamplingFactor=Integer.parseInt(resamplingTextField.getText());
  source.setSubsamplingFactor(MainDialog.this.maxImageSubsamplingFactor);
  target.setSubsamplingFactor(MainDialog.this.maxImageSubsamplingFactor);
}
Program: 26242
Project: 26242
Buggy source:
/** 
 * Ungray image. It restores the original version of the image (without mask).
 * @param pa point action pointer
 */
public void ungrayImage(final PointAction pa){
  if (pa == sourcePh.getPointAction()) {
    if (this.sourceImp != null && this.sourceImp.getProcessor() != null) {
      this.sourceImp.setProcessor(sourceImp.getTitle(),this.originalSourceIP);
      sourceImp.updateImage();
    }
  }
 else {
    if (this.targetImp != null && this.targetImp.getProcessor() != null) {
      this.targetImp.setProcessor(this.targetImp.getTitle(),this.originalTargetIP);
      targetImp.updateImage();
    }
  }
}

Fixed version (ground truth):
/** 
 * Ungray image. It restores the original version of the image (without mask).
 * @param pa point action pointer
 */
public void ungrayImage(final PointAction pa){
  if (sourcePh != null && pa == sourcePh.getPointAction()) {
    if (this.sourceImp != null && this.sourceImp.getProcessor() != null) {
      this.sourceImp.setProcessor(sourceImp.getTitle(),this.originalSourceIP);
      this.sourceImp.updateImage();
    }
  }
 else {
    if (this.targetImp != null && this.targetImp.getProcessor() != null) {
      this.targetImp.setProcessor(this.targetImp.getTitle(),this.originalTargetIP);
      targetImp.updateImage();
    }
  }
}
Program: 26243
Project: 26243
Buggy source:
/** 
 * Gives the least-squares solution to (A * x = b) such that (A^T * A)^-1 * A^T * b = x is a vector of size (column), where A is a (line x column) matrix, and where b is a vector of size (line). The result may differ from that obtained by a singular-value decomposition in the cases where the least-squares solution is not uniquely defined (SVD returns the solution of least norm, not QR).
 * @param A An input matrix A[line][column] of size (line x column)
 * @param b An input vector b[line] of size (line)
 * @return An output vector x[column] of size (column)
 */
public static double[] linearLeastSquares(final double[][] A,final double[] b){
  final int lines=A.length;
  final int columns=A[0].length;
  final double[][] Q=new double[lines][columns];
  final double[][] R=new double[columns][columns];
  final double[] x=new double[columns];
  double s;
  for (int i=0; (i < lines); i++) {
    for (int j=0; (j < columns); j++) {
      Q[i][j]=A[i][j];
    }
  }
  QRdecomposition(Q,R);
  for (int i=0; (i < columns); i++) {
    s=0.0F;
    for (int j=0; (j < lines); j++) {
      s+=Q[j][i] * b[j];
    }
    x[i]=s;
  }
  for (int i=columns - 1; (0 <= i); i--) {
    s=R[i][i];
    if ((s * s) == 0.0F) {
      x[i]=0.0F;
    }
 else {
      x[i]/=s;
    }
    for (int j=i - 1; (0 <= j); j--) {
      x[j]-=R[j][i] * x[i];
    }
  }
  return (x);
}

Fixed version (ground truth):
/** 
 * Gives the least-squares solution to (A * x = b) such that (A^T * A)^-1 * A^T * b = x is a vector of size (column), where A is a (line x column) matrix, and where b is a vector of size (line). The result may differ from that obtained by a singular-value decomposition in the cases where the least-squares solution is not uniquely defined (SVD returns the solution of least norm, not QR).
 * @param A An input matrix A[line][column] of size (line x column)
 * @param b An input vector b[line] of size (line)
 * @return An output vector x[column] of size (column)
 */
public static double[] linearLeastSquares(final double[][] A,final double[] b){
  if (A == null || A.length == 0)   return null;
  final int lines=A.length;
  final int columns=A[0].length;
  final double[][] Q=new double[lines][columns];
  final double[][] R=new double[columns][columns];
  final double[] x=new double[columns];
  double s;
  for (int i=0; (i < lines); i++) {
    for (int j=0; (j < columns); j++) {
      Q[i][j]=A[i][j];
    }
  }
  QRdecomposition(Q,R);
  for (int i=0; (i < columns); i++) {
    s=0.0F;
    for (int j=0; (j < lines); j++) {
      s+=Q[j][i] * b[j];
    }
    x[i]=s;
  }
  for (int i=columns - 1; (0 <= i); i--) {
    s=R[i][i];
    if ((s * s) == 0.0F) {
      x[i]=0.0F;
    }
 else {
      x[i]/=s;
    }
    for (int j=i - 1; (0 <= j); j--) {
      x[j]-=R[j][i] * x[i];
    }
  }
  return (x);
}
Program: 26244
Project: 26244
Buggy source:
/** 
 * 根据分割符从模板中取得变量的名字($$变量名$$) eg: $$aaa$$$$bbb$$ccc$$ 返回   aaa,bbb
 * @param templet 模板
 * @param split 包围变量名的字符串
 * @return 模板中的变量名
 */
public static Set<String> getParamNames(String templet,String split){
  Set<String> paramNames=new HashSet<String>();
  int start=0, end=0;
  while (end < templet.length()) {
    start=templet.indexOf(split,end) + split.length();
    if (start == -1) {
      break;
    }
    end=templet.indexOf(split,start);
    if (end == -1) {
      break;
    }
    paramNames.add(templet.substring(start,end));
    end=end + split.length();
  }
  return paramNames;
}

Fixed version (ground truth):
/** 
 * 根据分割符从模板中取得变量的名字($$变量名$$) eg: $$aaa$$$$bbb$$ccc$$ 返回   aaa,bbb
 * @param templet 模板
 * @param split 包围变量名的字符串
 * @return 模板中的变量名
 */
public static Set<String> getParamNames(String templet,String split){
  Set<String> paramNames=new HashSet<String>();
  int start=0, end=0;
  while (end < templet.length()) {
    start=templet.indexOf(split,end);
    if (start == -1) {
      break;
    }
    start=start + split.length();
    end=templet.indexOf(split,start);
    if (end == -1) {
      break;
    }
    paramNames.add(templet.substring(start,end));
    end=end + split.length();
  }
  return paramNames;
}
Program: 26245
Project: 26245
Buggy source:
@Override public void channelRead(final ChannelHandlerContext ctx,Object msg) throws Exception {
  if (!(msg instanceof HttpObject) || !(((HttpObject)msg).getDecoderResult().isSuccess())) {
    sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
  }
  HttpObject httpObject=(HttpObject)msg;
  messageQueue.add(httpObject);
  if (tunnelEstablished) {
    processQueuedMessages(ctx);
    return;
  }
  if (msg instanceof HttpRequest) {
    request=(HttpRequest)msg;
    try {
      requestUri=new URI(request.getUri());
    }
 catch (    URISyntaxException e) {
      sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
      return;
    }
    String hostHeaderValue=request.headers().get(HOST);
    requestedHost=getRequestedHost(requestUri,hostHeaderValue);
    if (requestedHost == null) {
      sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
      return;
    }
    VirtualHostConfig vhost=virtualHosts.get(requestedHost.getName());
    if (vhost == null) {
      sendError(ctx,HttpResponseStatus.SERVICE_UNAVAILABLE,null);
      return;
    }
    destinationHost=parseHost(vhost.getBalance().getMembers().iterator().next());
    connectToDestination(ctx,destinationHost);
  }
}

Fixed version (ground truth):
@Override public void channelRead(final ChannelHandlerContext ctx,Object msg) throws Exception {
  if (!(msg instanceof HttpObject) || !(((HttpObject)msg).getDecoderResult().isSuccess())) {
    sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
  }
  HttpObject httpObject=(HttpObject)msg;
  messageQueue.add(httpObject);
  if (tunnelEstablished) {
    processQueuedMessages(ctx);
    return;
  }
  if (msg instanceof HttpRequest) {
    HttpRequest request=(HttpRequest)msg;
    try {
      requestUri=new URI(request.getUri());
    }
 catch (    URISyntaxException e) {
      sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
      return;
    }
    String hostHeaderValue=request.headers().get(HOST);
    requestedHost=getRequestedHost(requestUri,hostHeaderValue);
    if (requestedHost == null) {
      sendError(ctx,HttpResponseStatus.BAD_REQUEST,null);
      return;
    }
    VirtualHostConfig vhost=virtualHosts.get(requestedHost.getName());
    if (vhost == null) {
      sendError(ctx,HttpResponseStatus.SERVICE_UNAVAILABLE,null);
      return;
    }
    destinationHost=parseHost(vhost.getBalance().getMembers().iterator().next());
    connectToDestination(ctx,destinationHost);
  }
}
Program: 26247
Project: 26247
Buggy source:
protected void calculateLegendOffsets(RectF offsets){
  offsets.left=0.f;
  offsets.right=0.f;
  offsets.top=0.f;
  offsets.bottom=0.f;
  if (mLegend != null && mLegend.isEnabled() && !mLegend.isDrawInsideEnabled()) {
switch (mLegend.getOrientation()) {
case VERTICAL:
switch (mLegend.getHorizontalAlignment()) {
case LEFT:
        offsets.left+=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getXOffset();
      break;
case RIGHT:
    offsets.right+=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getXOffset();
  break;
case CENTER:
switch (mLegend.getVerticalAlignment()) {
case TOP:
  offsets.top+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
case BOTTOM:
offsets.bottom+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
default :
break;
}
}
break;
case HORIZONTAL:
switch (mLegend.getVerticalAlignment()) {
case TOP:
offsets.top+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
if (getXAxis().isEnabled() && getXAxis().isDrawLabelsEnabled()) offsets.top+=getXAxis().mLabelRotatedHeight;
break;
case BOTTOM:
offsets.bottom+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
if (getXAxis().isEnabled() && getXAxis().isDrawLabelsEnabled()) offsets.bottom+=getXAxis().mLabelRotatedHeight;
break;
default :
break;
}
break;
}
}
}

Fixed version (ground truth):
protected void calculateLegendOffsets(RectF offsets){
  offsets.left=0.f;
  offsets.right=0.f;
  offsets.top=0.f;
  offsets.bottom=0.f;
  if (mLegend != null && mLegend.isEnabled() && !mLegend.isDrawInsideEnabled()) {
switch (mLegend.getOrientation()) {
case VERTICAL:
switch (mLegend.getHorizontalAlignment()) {
case LEFT:
        offsets.left+=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getXOffset();
      break;
case RIGHT:
    offsets.right+=Math.min(mLegend.mNeededWidth,mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent()) + mLegend.getXOffset();
  break;
case CENTER:
switch (mLegend.getVerticalAlignment()) {
case TOP:
  offsets.top+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
case BOTTOM:
offsets.bottom+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
default :
break;
}
}
break;
case HORIZONTAL:
switch (mLegend.getVerticalAlignment()) {
case TOP:
offsets.top+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
case BOTTOM:
offsets.bottom+=Math.min(mLegend.mNeededHeight,mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent()) + mLegend.getYOffset();
break;
default :
break;
}
break;
}
}
}