nus-yam/ex-repair huggingface dataset:
Program: 20779
Project: 20779
Buggy source:
public void testArtifactDownload() throws Exception {
  File file=proxy.get("String_Node_Str");
  assertTrue("String_Node_Str",file.exists());
  assertTrue("String_Node_Str",file.getAbsolutePath().startsWith(proxy.getConfiguration().getRepositoryCachePath()));
  file=proxy.get("String_Node_Str");
  try {
    file=proxy.get("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ResourceDoesNotExistException e) {
    assertTrue(true);
  }
}

Fixed version (ground truth):
public void testArtifactDownload() throws Exception {
  File file=proxy.get("String_Node_Str");
  assertTrue("String_Node_Str" + file.getAbsolutePath(),file.exists());
  assertTrue("String_Node_Str",file.getAbsolutePath().startsWith(proxy.getConfiguration().getRepositoryCachePath()));
  file=proxy.get("String_Node_Str");
  try {
    file=proxy.get("String_Node_Str");
    fail("String_Node_Str");
  }
 catch (  ResourceDoesNotExistException e) {
    assertTrue(true);
  }
}
Program: 20781
Project: 20781
Buggy source:
/** 
 * Create an index that will be used for testing. Indexing process: check if the object was already indexed [ checkIfIndexed(Object) ], open the index [ open() ], index the object [ index(Object) ], optimize the index [ optimize() ] and close the index [ close() ].
 * @throws Exception
 */
private EclipseRepositoryIndex createTestIndex() throws Exception {
  EclipseRepositoryIndex indexer=new EclipseRepositoryIndex(indexPath,repository,new DefaultDigester());
  Artifact artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  return indexer;
}

Fixed version (ground truth):
/** 
 * Create an index that will be used for testing. Indexing process: check if the object was already indexed [ checkIfIndexed(Object) ], open the index [ open() ], index the object [ index(Object) ], optimize the index [ optimize() ] and close the index [ close() ].
 * @throws Exception
 */
private EclipseRepositoryIndex createTestIndex() throws Exception {
  EclipseRepositoryIndex indexer=new EclipseRepositoryIndex(indexPath,repository,new DefaultDigester());
  Artifact artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  artifact.getFile().setLastModified(1137381114096L);
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  artifact=getArtifact("String_Node_Str","String_Node_Str","String_Node_Str");
  artifact.setFile(new File(repository.getBasedir(),repository.pathOf(artifact)));
  indexer.indexArtifact(artifact);
  indexer.optimize();
  indexer.close();
  return indexer;
}
Program: 20782
Project: 20782
Buggy source:
/** 
 * Validate the if the artifact exists in the specified location.
 * @param filename
 */
private boolean validateArtifactLocation(String filename){
  try {
    if (isLocal) {
      is=new FileInputStream(filename);
    }
 else {
      URL url=new URL(filename);
      is=url.openStream();
    }
    is.close();
  }
 catch (  Exception e) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Validate the if the artifact exists in the specified location.
 * @param filename
 */
private boolean validateArtifactLocation(String filename){
  return new File(filename).exists();
}
Program: 20784
Project: 20784
Buggy source:
/** 
 * Extract the contents of the artifact/jar file.
 * @param filename
 * @param groupId
 * @param artifactId
 */
private Model readArtifactModel(String filename,String groupId,String artifactId) throws ReportProcessorException {
  Model modelObj=null;
  JarFile jar=null;
  try {
    jar=new JarFile(filename);
    JarEntry entry=jar.getJarEntry("String_Node_Str" + groupId + "String_Node_Str"+ artifactId+ "String_Node_Str");
    if (entry != null) {
      InputStream entryStream=jar.getInputStream(entry);
      Reader isReader=new InputStreamReader(entryStream);
      try {
        MavenXpp3Reader pomReader=new MavenXpp3Reader();
        modelObj=pomReader.read(isReader);
      }
  finally {
        IOUtil.close(isReader);
      }
    }
  }
 catch (  IOException e) {
    throw new ReportProcessorException("String_Node_Str",e);
  }
catch (  XmlPullParserException e) {
    throw new ReportProcessorException("String_Node_Str",e);
  }
 finally {
    if (jar != null) {
      try {
        jar.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return modelObj;
}

Fixed version (ground truth):
/** 
 * Extract the contents of the artifact/jar file.
 * @param file
 * @param groupId
 * @param artifactId
 */
private Model readArtifactModel(File file,String groupId,String artifactId) throws ReportProcessorException {
  Model model=null;
  JarFile jar=null;
  try {
    jar=new JarFile(file);
    JarEntry entry=jar.getJarEntry("String_Node_Str" + groupId + "String_Node_Str"+ artifactId+ "String_Node_Str");
    if (entry != null) {
      model=readModel(jar.getInputStream(entry));
    }
  }
 catch (  IOException e) {
    throw new ReportProcessorException("String_Node_Str",e);
  }
catch (  XmlPullParserException e) {
    throw new ReportProcessorException("String_Node_Str",e);
  }
 finally {
    if (jar != null) {
      try {
        jar.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return model;
}
Program: 20785
Project: 20785
Buggy source:
void processMetadata(RepositoryMetadata metadata,ArtifactReporter reporter);

Fixed version (ground truth):
void processMetadata(RepositoryMetadata metadata,ArtifactRepository repository,ArtifactReporter reporter);
Program: 20787
Project: 20787
Buggy source:
private List<RichGauge> exportBatchGauges(JobExecution jobExecution){
  String jobExecutionIdentifier=MDC.get(LoggingListener.JOB_EXECUTION_IDENTIFIER);
  List<RichGauge> gauges=new ArrayList<RichGauge>();
  for (  RichGauge gauge : richGaugeRepository.findAll()) {
    if (gauge.getName().startsWith("String_Node_Str" + jobExecutionIdentifier)) {
      jobExecution.getExecutionContext().put("String_Node_Str" + gauge.getName().substring(("String_Node_Str" + jobExecutionIdentifier).length()),gauge);
      gauges.add(gauge);
      if (deleteMetricsOnJobFinish) {
        richGaugeRepository.reset(gauge.getName());
      }
    }
  }
  return gauges;
}

Fixed version (ground truth):
private List<RichGauge> exportBatchGauges(JobExecution jobExecution){
  String jobExecutionIdentifier=MDC.get(LoggingListener.JOB_EXECUTION_IDENTIFIER);
  List<RichGauge> gauges=new ArrayList<RichGauge>();
  for (  RichGauge gauge : richGaugeRepository.findAll()) {
    if (gauge.getName().startsWith("String_Node_Str" + jobExecutionIdentifier)) {
      jobExecution.getExecutionContext().put(gauge.getName().substring(("String_Node_Str" + jobExecutionIdentifier).length() + 1),gauge);
      gauges.add(gauge);
      if (deleteMetricsOnJobFinish) {
        richGaugeRepository.reset(gauge.getName());
      }
    }
  }
  return gauges;
}
Program: 20788
Project: 20788
Buggy source:
private List<Metric<?>> exportBatchMetrics(JobExecution jobExecution){
  String jobExecutionIdentifier=MDC.get(LoggingListener.JOB_EXECUTION_IDENTIFIER);
  List<Metric<?>> metrics=new ArrayList<Metric<?>>();
  for (  Metric<?> metric : metricRepository.findAll()) {
    if (metric.getName().startsWith("String_Node_Str" + jobExecutionIdentifier)) {
      if (metric.getValue() instanceof Long) {
        String key="String_Node_Str" + metric.getName().substring(("String_Node_Str" + jobExecutionIdentifier).length());
        Long newValue=(Long)metric.getValue();
        if (jobExecution.getExecutionContext().containsKey(key)) {
          Long oldValue=jobExecution.getExecutionContext().getLong(key);
          newValue+=oldValue;
          metric=metric.set(newValue);
        }
        jobExecution.getExecutionContext().putLong(key,newValue);
      }
      metrics.add(metric);
      if (deleteMetricsOnJobFinish) {
        metricRepository.reset(metric.getName());
      }
    }
  }
  return metrics;
}

Fixed version (ground truth):
private List<Metric<?>> exportBatchMetrics(JobExecution jobExecution){
  String jobExecutionIdentifier=MDC.get(LoggingListener.JOB_EXECUTION_IDENTIFIER);
  List<Metric<?>> metrics=new ArrayList<Metric<?>>();
  for (  Metric<?> metric : metricRepository.findAll()) {
    if (metric.getName().startsWith("String_Node_Str" + jobExecutionIdentifier)) {
      if (metric.getValue() instanceof Long) {
        String key=metric.getName().substring(("String_Node_Str" + jobExecutionIdentifier).length() + 1);
        Long newValue=(Long)metric.getValue();
        if (jobExecution.getExecutionContext().containsKey(key)) {
          Long oldValue=jobExecution.getExecutionContext().getLong(key);
          newValue+=oldValue;
          metric=metric.set(newValue);
        }
        jobExecution.getExecutionContext().putLong(key,newValue);
      }
      metrics.add(metric);
      if (deleteMetricsOnJobFinish) {
        metricRepository.reset(metric.getName());
      }
    }
  }
  return metrics;
}
Program: 20789
Project: 20789
Buggy source:
@Override public void afterCompletion(int status){
  if (status == STATUS_COMMITTED) {
    CounterContainer currentCounterContainer=counterContainer.get();
    for (    String incrementation : currentCounterContainer.incrementations) {
      delegate.increment(incrementation);
    }
    for (    String decrementation : currentCounterContainer.decrementations) {
      delegate.decrement(decrementation);
    }
    for (    String reset : currentCounterContainer.resets) {
      delegate.reset(reset);
    }
  }
  counterContainer.remove();
}

Fixed version (ground truth):
@Override public void afterCompletion(int status){
  if (status == STATUS_COMMITTED) {
    CounterContainer currentCounterContainer=counterContainer.get();
    for (    String incrementation : currentCounterContainer.incrementations) {
      delegate.increment(incrementation);
    }
    for (    String decrementation : currentCounterContainer.decrementations) {
      delegate.decrement(decrementation);
    }
    for (    String reset : currentCounterContainer.resets) {
      delegate.reset(reset);
    }
  }
  counterContainer.remove();
  if (TransactionSynchronizationManager.hasResource(serviceKey)) {
    TransactionSynchronizationManager.unbindResource(serviceKey);
  }
}
Program: 20790
Project: 20790
Buggy source:
public String process(String item) throws Exception {
  log.info(item);
  businessMetrics.incrementNonTransactional("String_Node_Str");
  return item;
}

Fixed version (ground truth):
public String process(String item) throws Exception {
  log.info(item);
  businessMetrics.increment("String_Node_Str");
  return item;
}
Program: 20791
Project: 20791
Buggy source:
@Test public void testRunJob() throws InterruptedException {
  Long executionId=restTemplate.postForObject("String_Node_Str","String_Node_Str",Long.class);
  while (!restTemplate.getForObject("String_Node_Str",String.class,executionId).equals("String_Node_Str")) {
    Thread.sleep(1000);
  }
  String log=restTemplate.getForObject("String_Node_Str",String.class,executionId);
  assertThat(log.length() > 20,is(true));
  JobExecution jobExecution=jobExplorer.getJobExecution(executionId);
  assertThat(jobExecution.getStatus(),is(BatchStatus.COMPLETED));
  String jobExecutionString=restTemplate.getForObject("String_Node_Str",String.class,executionId);
  assertThat(jobExecutionString.contains("String_Node_Str"),is(true));
  assertThat((Long)metricRepository.findOne("String_Node_Str").getValue(),is(2l));
}

Fixed version (ground truth):
@Test public void testRunJob() throws InterruptedException {
  Long executionId=restTemplate.postForObject("String_Node_Str","String_Node_Str",Long.class);
  while (!restTemplate.getForObject("String_Node_Str",String.class,executionId).equals("String_Node_Str")) {
    Thread.sleep(1000);
  }
  String log=restTemplate.getForObject("String_Node_Str",String.class,executionId);
  assertThat(log.length() > 20,is(true));
  JobExecution jobExecution=jobExplorer.getJobExecution(executionId);
  assertThat(jobExecution.getStatus(),is(BatchStatus.COMPLETED));
  String jobExecutionString=restTemplate.getForObject("String_Node_Str",String.class,executionId);
  assertThat(jobExecutionString.contains("String_Node_Str"),is(true));
  assertThat((Long)metricRepository.findOne("String_Node_Str").getValue(),is(7l));
}
Program: 20792
Project: 20792
Buggy source:
@Override public void run(){
  for (  RecognitionListener l : listeners)   l.onVadStateChanged(state);
}

Fixed version (ground truth):
@Override public void run(){
  RecognitionListener[] emptyArray=new RecognitionListener[0];
  for (  RecognitionListener listener : listeners.toArray(emptyArray))   listener.onVadStateChanged(state);
}
Program: 20793
Project: 20793
Buggy source:
public void removeListener(RecognitionListener listener){
  listeners.remove(listener);
}

Fixed version (ground truth):
public void removeListener(RecognitionListener listener){
synchronized (listeners) {
    listeners.remove(listener);
  }
}
Program: 20794
Project: 20794
Buggy source:
public void addListener(RecognitionListener listener){
  listeners.add(listener);
}

Fixed version (ground truth):
public void addListener(RecognitionListener listener){
synchronized (listeners) {
    listeners.add(listener);
  }
}
Program: 20795
Project: 20795
Buggy source:
/** 
 * Constructor.
 */
public LocationServiceImpl(){
  _telnet=new TelnetWrapper();
}

Fixed version (ground truth):
/** 
 * Constructor.
 */
public LocationServiceImpl(){
  _telnet=new TelnetWrapper();
  final String home=System.getProperty("String_Node_Str");
  final File authTokenFile=new File(home,"String_Node_Str");
  try {
    _emulator_console_auth_token=new Scanner(authTokenFile).useDelimiter("String_Node_Str").next();
    logger.info("String_Node_Str" + _emulator_console_auth_token);
  }
 catch (  IOException ioe) {
    logger.log(Level.SEVERE,"String_Node_Str" + authTokenFile.getAbsolutePath(),ioe);
  }
}
Program: 20796
Project: 20796
Buggy source:
/** 
 * {@inheritDoc}
 */
public void setPort(final int port) throws IOException {
  _telnet.disconnect();
  _telnet.connect("String_Node_Str",port);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public void setPort(final int port) throws IOException {
  _telnet.disconnect();
  logger.info("String_Node_Str" + port);
  _telnet.connect("String_Node_Str",port);
  if (_emulator_console_auth_token == null) {
    logger.info("String_Node_Str");
  }
 else {
    logger.info("String_Node_Str" + _emulator_console_auth_token);
    _telnet.send("String_Node_Str" + _emulator_console_auth_token);
  }
}
Program: 20797
Project: 20797
Buggy source:
@Override public void playMedia(final String url,final String mimeType,final String title,final String description,final String iconSrc,final boolean shouldLoop,final LaunchListener listener){
  ConnectionListener connectionListener=new ConnectionListener(){
    @Override public void onConnected(){
      MediaMetadata mMediaMetadata=new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
      mMediaMetadata.putString(MediaMetadata.KEY_TITLE,title);
      mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE,description);
      if (iconSrc != null) {
        Uri iconUri=Uri.parse(iconSrc);
        WebImage image=new WebImage(iconUri,100,100);
        mMediaMetadata.addImage(image);
      }
      MediaInfo mediaInfo=new MediaInfo.Builder(url).setContentType(mimeType).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mMediaMetadata).build();
      Cast.CastApi.launchApplication(mApiClient,CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID,false).setResultCallback(new ApplicationConnectionResultCallback(mediaInfo,listener));
    }
  }
;
  runCommand(connectionListener);
}

Fixed version (ground truth):
@Override public void playMedia(final String url,final String mimeType,final String title,final String description,final String iconSrc,final boolean shouldLoop,final LaunchListener listener){
  ConnectionListener connectionListener=new ConnectionListener(){
    @Override public void onConnected(){
      String mediaAppId=CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
      MediaMetadata mMediaMetadata=new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
      mMediaMetadata.putString(MediaMetadata.KEY_TITLE,title);
      mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE,description);
      if (iconSrc != null) {
        Uri iconUri=Uri.parse(iconSrc);
        WebImage image=new WebImage(iconUri,100,100);
        mMediaMetadata.addImage(image);
      }
      MediaInfo mediaInfo=new MediaInfo.Builder(url).setContentType(mimeType).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mMediaMetadata).build();
      boolean relaunchIfRunning=false;
      if (Cast.CastApi.getApplicationStatus(mApiClient) != null && mediaAppId.equals(currentAppId)) {
        relaunchIfRunning=false;
      }
 else {
        relaunchIfRunning=true;
      }
      Cast.CastApi.launchApplication(mApiClient,mediaAppId,relaunchIfRunning).setResultCallback(new ApplicationConnectionResultCallback(mediaInfo,listener));
    }
  }
;
  runCommand(connectionListener);
}
Program: 20798
Project: 20798
Buggy source:
@Override public void displayImage(final String url,final String mimeType,final String title,final String description,final String iconSrc,final LaunchListener listener){
  ConnectionListener connectionListener=new ConnectionListener(){
    @Override public void onConnected(){
      MediaMetadata mMediaMetadata=new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
      mMediaMetadata.putString(MediaMetadata.KEY_TITLE,title);
      mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE,description);
      if (iconSrc != null) {
        Uri iconUri=Uri.parse(iconSrc);
        WebImage image=new WebImage(iconUri,100,100);
        mMediaMetadata.addImage(image);
      }
      MediaInfo mediaInfo=new MediaInfo.Builder(url).setContentType(mimeType).setStreamType(MediaInfo.STREAM_TYPE_NONE).setMetadata(mMediaMetadata).build();
      Cast.CastApi.launchApplication(mApiClient,CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID,false).setResultCallback(new ApplicationConnectionResultCallback(mediaInfo,listener));
    }
  }
;
  runCommand(connectionListener);
}

Fixed version (ground truth):
@Override public void displayImage(final String url,final String mimeType,final String title,final String description,final String iconSrc,final LaunchListener listener){
  ConnectionListener connectionListener=new ConnectionListener(){
    @Override public void onConnected(){
      String mediaAppId=CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
      MediaMetadata mMediaMetadata=new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
      mMediaMetadata.putString(MediaMetadata.KEY_TITLE,title);
      mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE,description);
      if (iconSrc != null) {
        Uri iconUri=Uri.parse(iconSrc);
        WebImage image=new WebImage(iconUri,100,100);
        mMediaMetadata.addImage(image);
      }
      MediaInfo mediaInfo=new MediaInfo.Builder(url).setContentType(mimeType).setStreamType(MediaInfo.STREAM_TYPE_NONE).setMetadata(mMediaMetadata).build();
      boolean relaunchIfRunning=false;
      if (Cast.CastApi.getApplicationStatus(mApiClient) != null && mediaAppId.equals(currentAppId)) {
        relaunchIfRunning=false;
      }
 else {
        relaunchIfRunning=true;
      }
      Cast.CastApi.launchApplication(mApiClient,mediaAppId,relaunchIfRunning).setResultCallback(new ApplicationConnectionResultCallback(mediaInfo,listener));
    }
  }
;
  runCommand(connectionListener);
}
Program: 20800
Project: 20800
Buggy source:
private void sendP2PMessage(Object message,final ResponseListener<Object> listener){
  JSONObject _payload=new JSONObject();
  try {
    _payload.put("String_Node_Str","String_Node_Str");
    _payload.put("String_Node_Str",getFullAppId());
    _payload.put("String_Node_Str",message);
  }
 catch (  JSONException ex) {
  }
  final JSONObject payload=_payload;
  if (isConnected()) {
    socket.sendMessage(payload,null);
    if (listener != null)     listener.onSuccess(null);
  }
 else {
    ResponseListener<Object> joinListener=new ResponseListener<Object>(){
      @Override public void onError(      ServiceCommandError error){
        if (listener != null)         listener.onError(error);
      }
      @Override public void onSuccess(      Object object){
        socket.sendMessage(payload,null);
        if (listener != null)         listener.onSuccess(null);
      }
    }
;
    join(joinListener);
  }
}

Fixed version (ground truth):
private void sendP2PMessage(final Object message,final ResponseListener<Object> listener){
  JSONObject _payload=new JSONObject();
  try {
    _payload.put("String_Node_Str","String_Node_Str");
    _payload.put("String_Node_Str",getFullAppId());
    _payload.put("String_Node_Str",message);
  }
 catch (  JSONException ex) {
  }
  final JSONObject payload=_payload;
  if (isConnected()) {
    socket.sendMessage(payload,null);
    if (listener != null)     listener.onSuccess(null);
  }
 else {
    ResponseListener<Object> connectListener=new ResponseListener<Object>(){
      @Override public void onError(      ServiceCommandError error){
        if (listener != null)         listener.onError(error);
      }
      @Override public void onSuccess(      Object object){
        sendP2PMessage(message,listener);
      }
    }
;
    connect(connectListener);
  }
}
Program: 20802
Project: 20802
Buggy source:
@Override public Boolean onReceiveMessage(JSONObject payload){
  String type=payload.optString("String_Node_Str");
  if ("String_Node_Str".equals(type)) {
    String fromAppId=null;
    fromAppId=payload.optString("String_Node_Str");
    if (!fromAppId.equalsIgnoreCase(getFullAppId()))     return false;
    Object message=payload.opt("String_Node_Str");
    if (message instanceof JSONObject) {
      JSONObject messageJSON=(JSONObject)message;
      String contentType=messageJSON.optString("String_Node_Str");
      Integer contentTypeIndex=contentType.lastIndexOf("String_Node_Str");
      if (contentType != null && contentTypeIndex >= 0) {
        String payloadKey=contentType.substring(contentTypeIndex);
        if (payloadKey == null || payloadKey.length() == 0)         return false;
        JSONObject messagePayload=messageJSON.optJSONObject("String_Node_Str");
        if (messagePayload == null)         return false;
        if (payloadKey.equalsIgnoreCase("String_Node_Str"))         handleMediaEvent(messagePayload);
 else         if (payloadKey.equalsIgnoreCase("String_Node_Str"))         handleMediaCommandResponse(messagePayload);
      }
 else {
        handleMessage(messageJSON);
      }
    }
 else     if (message instanceof String) {
      handleMessage(message);
    }
    return false;
  }
  return true;
}

Fixed version (ground truth):
@Override public Boolean onReceiveMessage(JSONObject payload){
  String type=payload.optString("String_Node_Str");
  if ("String_Node_Str".equals(type)) {
    String fromAppId=null;
    fromAppId=payload.optString("String_Node_Str");
    if (!fromAppId.equalsIgnoreCase(getFullAppId()))     return false;
    Object message=payload.opt("String_Node_Str");
    if (message instanceof JSONObject) {
      JSONObject messageJSON=(JSONObject)message;
      String contentType=messageJSON.optString("String_Node_Str");
      Integer contentTypeIndex=contentType.indexOf("String_Node_Str");
      if (contentType != null && contentTypeIndex >= 0) {
        String payloadKey=contentType.split("String_Node_Str")[1];
        if (payloadKey == null || payloadKey.length() == 0)         return false;
        JSONObject messagePayload=messageJSON.optJSONObject(payloadKey);
        if (messagePayload == null)         return false;
        if (payloadKey.equalsIgnoreCase("String_Node_Str"))         handleMediaEvent(messagePayload);
 else         if (payloadKey.equalsIgnoreCase("String_Node_Str"))         handleMediaCommandResponse(messagePayload);
      }
 else {
        handleMessage(messageJSON);
      }
    }
 else     if (message instanceof String) {
      handleMessage(message);
    }
    return false;
  }
  return true;
}
Program: 20803
Project: 20803
Buggy source:
public void disconnectFromWebApp(final WebOSWebAppSession webAppSession){
  JSONObject rawData=(JSONObject)webAppSession.launchSession.getRawData();
  String appId=null;
  try {
    appId=rawData.getString("String_Node_Str");
  }
 catch (  JSONException ex) {
  }
  if (appId == null) {
    Enumeration<String> enumeration=mAppToAppMessageListeners.keys();
    while (enumeration.hasMoreElements()) {
      String key=enumeration.nextElement();
      if (key.contains(webAppSession.launchSession.getAppId())) {
        appId=key;
        break;
      }
    }
  }
  if (appId != null)   mAppToAppMessageListeners.remove(appId);
  ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.remove(appId);
  if (connectionSubscription != null) {
    if (!this.serviceDescription.getVersion().contains("String_Node_Str")) {
      connectionSubscription.unsubscribe();
    }
  }
  if (webAppSession.getWebAppSessionListener() != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
      }
    }
);
  }
}

Fixed version (ground truth):
public void disconnectFromWebApp(final WebOSWebAppSession webAppSession){
  JSONObject rawData=(JSONObject)webAppSession.launchSession.getRawData();
  String appId=null;
  try {
    appId=rawData.getString("String_Node_Str");
  }
 catch (  JSONException ex) {
  }
  if (appId == null && mAppToAppMessageListeners != null) {
    Enumeration<String> enumeration=mAppToAppMessageListeners.keys();
    while (enumeration.hasMoreElements()) {
      String key=enumeration.nextElement();
      if (key.contains(webAppSession.launchSession.getAppId())) {
        appId=key;
        break;
      }
    }
  }
  if (appId != null)   mAppToAppMessageListeners.remove(appId);
  ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.remove(appId);
  if (connectionSubscription != null) {
    if (!this.serviceDescription.getVersion().contains("String_Node_Str")) {
      connectionSubscription.unsubscribe();
    }
  }
  if (webAppSession.getWebAppSessionListener() != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
      }
    }
);
  }
}
Program: 20804
Project: 20804
Buggy source:
protected void reportConnected(boolean ready){
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (listener != null)       listener.onConnectionSuccess(DeviceService.this);
    }
  }
);
}

Fixed version (ground truth):
protected void reportConnected(boolean ready){
  if (listener == null)   return;
  if (listener instanceof ConnectableDevice)   listener.onConnectionSuccess(this);
 else {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        if (listener != null)         listener.onConnectionSuccess(DeviceService.this);
      }
    }
);
  }
}
Program: 20805
Project: 20805
Buggy source:
public void sendSearch(){
  List<String> killKeys=new ArrayList<String>();
  long killPoint=new Date().getTime() - SSDP_TIMEOUT;
  for (  String key : foundServices.keySet()) {
    ServiceDescription service=foundServices.get(key);
    if (service.getLastDetection() < killPoint) {
      killKeys.add(key);
    }
  }
  for (  String key : killKeys) {
    final ServiceDescription service=foundServices.get(key);
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        for (        DiscoveryProviderListener listener : serviceListeners) {
          listener.onServiceRemoved(SSDPDiscoveryProvider.this,service);
        }
      }
    }
);
    foundServices.remove(key);
  }
  for (  JSONObject searchTarget : serviceFilters) {
    SSDPSearchMsg search=null;
    try {
      search=new SSDPSearchMsg(searchTarget.getString("String_Node_Str"));
    }
 catch (    JSONException e) {
      e.printStackTrace();
      return;
    }
    final String message=search.toString();
    Timer timer=new Timer();
    for (int i=0; i < 3; i++) {
      TimerTask task=new TimerTask(){
        @Override public void run(){
          try {
            if (mSSDPSocket != null)             mSSDPSocket.send(message);
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
      }
;
      timer.schedule(task,i * 1000);
    }
  }
  ;
}

Fixed version (ground truth):
public void sendSearch(){
  List<String> killKeys=new ArrayList<String>();
  long killPoint=new Date().getTime() - SSDP_TIMEOUT;
  for (  String key : foundServices.keySet()) {
    ServiceDescription service=foundServices.get(key);
    if (service == null || service.getLastDetection() < killPoint) {
      killKeys.add(key);
    }
  }
  for (  String key : killKeys) {
    final ServiceDescription service=foundServices.get(key);
    if (service != null) {
      Util.runOnUI(new Runnable(){
        @Override public void run(){
          for (          DiscoveryProviderListener listener : serviceListeners) {
            listener.onServiceRemoved(SSDPDiscoveryProvider.this,service);
          }
        }
      }
);
    }
    if (foundServices.containsKey(key))     foundServices.remove(key);
  }
  for (  JSONObject searchTarget : serviceFilters) {
    SSDPSearchMsg search=null;
    try {
      search=new SSDPSearchMsg(searchTarget.getString("String_Node_Str"));
    }
 catch (    JSONException e) {
      e.printStackTrace();
      return;
    }
    final String message=search.toString();
    Timer timer=new Timer();
    for (int i=0; i < 3; i++) {
      TimerTask task=new TimerTask(){
        @Override public void run(){
          try {
            if (mSSDPSocket != null)             mSSDPSocket.send(message);
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
      }
;
      timer.schedule(task,i * 1000);
    }
  }
  ;
}
Program: 20806
Project: 20806
Buggy source:
@Override public void disconnect(){
  Log.d("String_Node_Str","String_Node_Str" + serviceDescription.getIpAddress());
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (listener != null)       listener.onDisconnect(WebOSTVService.this,null);
    }
  }
);
  if (socket != null) {
    socket.setListener(null);
    socket.disconnect();
    socket=null;
  }
  if (mAppToAppIdMappings != null)   mAppToAppIdMappings.clear();
  if (mWebAppSessions != null)   mWebAppSessions.clear();
}

Fixed version (ground truth):
@Override public void disconnect(){
  Log.d("String_Node_Str","String_Node_Str" + serviceDescription.getIpAddress());
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (listener != null)       listener.onDisconnect(WebOSTVService.this,null);
    }
  }
);
  if (socket != null) {
    socket.setListener(null);
    socket.disconnect();
    socket=null;
  }
  if (mAppToAppIdMappings != null)   mAppToAppIdMappings.clear();
  if (mWebAppSessions != null) {
    Enumeration<WebOSWebAppSession> iterator=mWebAppSessions.elements();
    while (iterator.hasMoreElements()) {
      WebOSWebAppSession session=iterator.nextElement();
      session.disconnectFromWebApp();
    }
    mWebAppSessions.clear();
  }
}
Program: 20807
Project: 20807
Buggy source:
@Override public void unsubscribe(URLServiceSubscription<?> subscription){
  socket.unsubscribe(subscription);
}

Fixed version (ground truth):
@Override public void unsubscribe(URLServiceSubscription<?> subscription){
  if (socket != null)   socket.unsubscribe(subscription);
}
Program: 20808
Project: 20808
Buggy source:
@Override public void sendCommand(ServiceCommand<?> command){
  socket.sendCommand(command);
}

Fixed version (ground truth):
@Override public void sendCommand(ServiceCommand<?> command){
  if (socket != null)   socket.sendCommand(command);
}
Program: 20809
Project: 20809
Buggy source:
@Override public void run(){
  getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
}

Fixed version (ground truth):
@Override public void run(){
  if (getWebAppSessionListener() != null)   getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
}
Program: 20810
Project: 20810
Buggy source:
public void handleMessage(final Object message){
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
    }
  }
);
}

Fixed version (ground truth):
public void handleMessage(final Object message){
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (getWebAppSessionListener() != null)       getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
    }
  }
);
}
Program: 20811
Project: 20811
Buggy source:
public void disconnectFromWebApp(final WebOSWebAppSession webAppSession){
  JSONObject rawData=(JSONObject)webAppSession.launchSession.getRawData();
  String appId=null;
  try {
    appId=rawData.getString("String_Node_Str");
  }
 catch (  JSONException ex) {
  }
  if (appId == null) {
    Enumeration<String> enumeration=mAppToAppMessageListeners.keys();
    while (enumeration.hasMoreElements()) {
      String key=enumeration.nextElement();
      if (key.contains(webAppSession.launchSession.getAppId())) {
        appId=key;
        break;
      }
    }
  }
  if (appId != null)   mAppToAppMessageListeners.remove(appId);
  ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.remove(appId);
  if (connectionSubscription != null) {
    if (!this.serviceDescription.getVersion().contains("String_Node_Str")) {
      connectionSubscription.unsubscribe();
    }
  }
  if (webAppSession.getWebAppSessionListener() != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
      }
    }
);
  }
}

Fixed version (ground truth):
public void disconnectFromWebApp(final WebOSWebAppSession webAppSession){
  JSONObject rawData=(JSONObject)webAppSession.launchSession.getRawData();
  String appId=null;
  try {
    appId=rawData.getString("String_Node_Str");
  }
 catch (  JSONException ex) {
  }
  if (appId == null && mAppToAppMessageListeners != null) {
    Enumeration<String> enumeration=mAppToAppMessageListeners.keys();
    while (enumeration.hasMoreElements()) {
      String key=enumeration.nextElement();
      if (key.contains(webAppSession.launchSession.getAppId())) {
        appId=key;
        break;
      }
    }
  }
  if (appId != null)   mAppToAppMessageListeners.remove(appId);
  ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.remove(appId);
  if (connectionSubscription != null) {
    if (!this.serviceDescription.getVersion().contains("String_Node_Str")) {
      connectionSubscription.unsubscribe();
    }
  }
  if (webAppSession.getWebAppSessionListener() != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
      }
    }
);
  }
}
Program: 20813
Project: 20813
Buggy source:
/** 
 * Registers a commonly-used set of DeviceServices with DiscoveryManager. This method will be called on first call of startDiscovery if no DeviceServices have been registered. - CastDiscoveryProvider + CastService - SSDPDiscoveryProvider + DIALService + DLNAService (limited to LG TVs, currently) + NetcastTVService + RokuService + WebOSTVService - AirPlayDiscoveryProvider + AirPlayService
 */
public void registerDefaultDeviceTypes(){
  registerDeviceService(WebOSTVService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(DLNAService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(DIALService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(RokuService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(CastService.class,CastDiscoveryProvider.class);
  registerDeviceService(AirPlayService.class,ZeroconfDiscoveryProvider.class);
}

Fixed version (ground truth):
/** 
 * Registers a commonly-used set of DeviceServices with DiscoveryManager. This method will be called on first call of startDiscovery if no DeviceServices have been registered. - CastDiscoveryProvider + CastService - SSDPDiscoveryProvider + DIALService + DLNAService (limited to LG TVs, currently) + NetcastTVService + RokuService + WebOSTVService - ZeroconfDiscoveryProvider + AirPlayService
 */
public void registerDefaultDeviceTypes(){
  registerDeviceService(WebOSTVService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(DLNAService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(DIALService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(RokuService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(CastService.class,CastDiscoveryProvider.class);
  registerDeviceService(AirPlayService.class,ZeroconfDiscoveryProvider.class);
}
Program: 20814
Project: 20814
Buggy source:
private void openSocket(){
  if (mSSDPSocket != null && mSSDPSocket.isConnected())   return;
  WifiManager wifiMgr=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiInfo=wifiMgr.getConnectionInfo();
  int ip=wifiInfo.getIpAddress();
  if (ip == 0)   return;
  byte[] ipAddress=Util.convertIpAddress(ip);
  try {
    InetAddress source=InetAddress.getByAddress(ipAddress);
    mSSDPSocket=new SSDPSocket(source);
  }
 catch (  UnknownHostException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void openSocket(){
  if (mSSDPSocket != null && mSSDPSocket.isConnected())   return;
  try {
    InetAddress source=Util.getIpAddress(context);
    if (source == null)     return;
    mSSDPSocket=new SSDPSocket(source);
  }
 catch (  UnknownHostException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
Program: 20815
Project: 20815
Buggy source:
public ZeroconfDiscoveryProvider(Context context){
  initJmDNS();
  services=new ConcurrentHashMap<String,ServiceDescription>(8,0.75f,2);
  serviceListeners=new CopyOnWriteArrayList<DiscoveryProviderListener>();
  serviceFilters=new ArrayList<JSONObject>();
}

Fixed version (ground truth):
public ZeroconfDiscoveryProvider(Context context){
  initJmDNS(context);
  services=new ConcurrentHashMap<String,ServiceDescription>(8,0.75f,2);
  serviceListeners=new CopyOnWriteArrayList<DiscoveryProviderListener>();
  serviceFilters=new ArrayList<JSONObject>();
}
Program: 20816
Project: 20816
Buggy source:
private void initJmDNS(){
  Util.runInBackground(new Runnable(){
    @Override public void run(){
      try {
        jmdns=JmDNS.create();
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
    }
  }
);
}

Fixed version (ground truth):
private void initJmDNS(final Context context){
  Util.runInBackground(new Runnable(){
    @Override public void run(){
      try {
        InetAddress source=Util.getIpAddress(context);
        if (source == null)         return;
        jmdns=JmDNS.create(source,HOSTNAME);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
    }
  }
);
}
Program: 20817
Project: 20817
Buggy source:
@Override public void closeInputPicker(LaunchSession launchSession,ResponseListener<Object> listener){
  if (inputPickerSession != null) {
    inputPickerSession.close(listener);
  }
}

Fixed version (ground truth):
@Override public void closeInputPicker(LaunchSession launchSession,ResponseListener<Object> listener){
  this.getKeyControl().sendKeyCode(VirtualKeycodes.EXIT.getCode(),listener);
}
Program: 20818
Project: 20818
Buggy source:
public DeviceService(ServiceConfig serviceConfig){
  this.serviceConfig=serviceConfig;
  mCapabilities=new ArrayList<String>();
  setCapabilities();
}

Fixed version (ground truth):
public DeviceService(ServiceConfig serviceConfig){
  this.serviceConfig=serviceConfig;
  mCapabilities=new ArrayList<String>();
  updateCapabilities();
}
Program: 20819
Project: 20819
Buggy source:
protected void setCapabilities(){
}

Fixed version (ground truth):
protected void setCapabilities(List<String> newCapabilities){
  List<String> oldCapabilities=mCapabilities;
  mCapabilities=newCapabilities;
  List<String> _lostCapabilities=new ArrayList<String>();
  for (  String capability : oldCapabilities) {
    if (!newCapabilities.contains(capability))     _lostCapabilities.add(capability);
  }
  List<String> _addedCapabilities=new ArrayList<String>();
  for (  String capability : newCapabilities) {
    if (!oldCapabilities.contains(capability))     _addedCapabilities.add(capability);
  }
  final List<String> lostCapabilities=_lostCapabilities;
  final List<String> addedCapabilities=_addedCapabilities;
  if (this.listener != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        listener.onCapabilitiesUpdated(DeviceService.this,addedCapabilities,lostCapabilities);
      }
    }
);
  }
}
Program: 20822
Project: 20822
Buggy source:
@Override public void launchNetflix(String contentId,Launcher.AppLaunchListener listener){
  JSONObject params=new JSONObject();
  try {
    params.put("String_Node_Str",contentId);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  AppInfo appInfo=new AppInfo(){
{
      setId("String_Node_Str");
      setName("String_Node_Str");
    }
  }
;
  launchAppWithInfo(appInfo,params,listener);
}

Fixed version (ground truth):
@Override public void launchNetflix(String contentId,Launcher.AppLaunchListener listener){
  JSONObject params=new JSONObject();
  String netflixContentId="String_Node_Str" + contentId + "String_Node_Str";
  try {
    params.put("String_Node_Str",netflixContentId);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  AppInfo appInfo=new AppInfo(){
{
      setId("String_Node_Str");
      setName("String_Node_Str");
    }
  }
;
  launchAppWithInfo(appInfo,params,listener);
}
Program: 20823
Project: 20823
Buggy source:
@Override public void setServiceDescription(ServiceDescription serviceDescription){
  super.setServiceDescription(serviceDescription);
  if (this.serviceDescription != null)   this.serviceDescription.setPort(8060);
}

Fixed version (ground truth):
@Override public void setServiceDescription(ServiceDescription serviceDescription){
  super.setServiceDescription(serviceDescription);
  if (this.serviceDescription != null)   this.serviceDescription.setPort(8060);
  probeForAppSupport();
}
Program: 20824
Project: 20824
Buggy source:
/** 
 * Registers an app ID to be checked upon discovery of this device. If the app is found on the target device, the RokuService will gain the "Launcher.<appID>" capability, where <appID> is the value of the appId parameter. This method must be called before starting DiscoveryManager for the first time.
 * @param appId ID of the app to be checked for
 */
public static void registerApp(String appId){
  if (registeredApps.contains(appId))   registeredApps.add(appId);
}

Fixed version (ground truth):
/** 
 * Registers an app ID to be checked upon discovery of this device. If the app is found on the target device, the RokuService will gain the "Launcher.<appID>" capability, where <appID> is the value of the appId parameter. This method must be called before starting DiscoveryManager for the first time.
 * @param appId ID of the app to be checked for
 */
public static void registerApp(String appId){
  if (!registeredApps.contains(appId))   registeredApps.add(appId);
}
Program: 20825
Project: 20825
Buggy source:
public RokuService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  httpClient=new DefaultHttpClient();
  ClientConnectionManager mgr=httpClient.getConnectionManager();
  HttpParams params=httpClient.getParams();
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
  probeForAppSupport();
}

Fixed version (ground truth):
public RokuService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  httpClient=new DefaultHttpClient();
  ClientConnectionManager mgr=httpClient.getConnectionManager();
  HttpParams params=httpClient.getParams();
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
}
Program: 20826
Project: 20826
Buggy source:
@Override public void closeApp(LaunchSession launchSession,ResponseListener<Object> listener){
  String uri="String_Node_Str";
  String appId=launchSession.getAppId();
  JSONObject payload=new JSONObject();
  try {
    payload.put("String_Node_Str",appId);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  ServiceCommand<ResponseListener<Object>> request=new ServiceCommand<ResponseListener<Object>>(launchSession.getService(),uri,payload,true,listener);
  request.send();
}

Fixed version (ground truth):
@Override public void closeApp(LaunchSession launchSession,ResponseListener<Object> listener){
  String uri="String_Node_Str";
  String appId=launchSession.getAppId();
  String sessionId=launchSession.getSessionId();
  JSONObject payload=new JSONObject();
  try {
    payload.put("String_Node_Str",appId);
    payload.put("String_Node_Str",sessionId);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  ServiceCommand<ResponseListener<Object>> request=new ServiceCommand<ResponseListener<Object>>(launchSession.getService(),uri,payload,true,listener);
  request.send();
}