Program: 20853
Project: 20853
Buggy source:
public void connectToWebApp(final WebOSWebAppSession webAppSession,final boolean joinOnly,final ResponseListener<Object> connectionListener){
  if (webAppSession == null || webAppSession.launchSession == null) {
    Util.postError(connectionListener,new ServiceCommandError(0,"String_Node_Str",null));
    return;
  }
  if (webAppSession.messageHandler == null) {
    Util.postError(connectionListener,new ServiceCommandError(-1,"String_Node_Str",null));
    return;
  }
  String _fullAppId=null;
  String _subscriptionKey=null;
  String _idKey=null;
  if (webAppSession.launchSession.getSessionType() == LaunchSession.LaunchSessionType.WebApp) {
    _fullAppId=String.format("String_Node_Str",webAppSession.launchSession.getAppId());
    _subscriptionKey=webAppSession.launchSession.getAppId();
    _idKey="String_Node_Str";
  }
 else   if (webAppSession.launchSession.getSessionType() == LaunchSession.LaunchSessionType.App) {
    _fullAppId=_subscriptionKey=webAppSession.launchSession.getAppId();
    _idKey="String_Node_Str";
  }
  if (_fullAppId == null || _fullAppId.length() == 0) {
    Util.postError(connectionListener,new ServiceCommandError(-1,"String_Node_Str",null));
    return;
  }
  final String fullAppId=_fullAppId;
  final String subscriptionKey=_subscriptionKey;
  final String idKey=_idKey;
  String uri="String_Node_Str";
  JSONObject payload=new JSONObject();
  try {
    payload.put(idKey,subscriptionKey);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  ResponseListener<Object> responseListener=new ResponseListener<Object>(){
    @Override public void onSuccess(    final Object response){
      JSONObject jsonObj=(JSONObject)response;
      String state=jsonObj.optString("String_Node_Str");
      if (!state.equalsIgnoreCase("String_Node_Str")) {
        if (joinOnly && state.equalsIgnoreCase("String_Node_Str")) {
          Util.postError(connectionListener,new ServiceCommandError(0,"String_Node_Str",null));
        }
        return;
      }
      String appId=jsonObj.optString("String_Node_Str");
      if (appId != null && appId.length() != 0) {
        mAppToAppMessageListeners.put(appId,webAppSession.messageHandler);
        JSONObject newRawData;
        if (webAppSession.launchSession.getRawData() != null)         newRawData=(JSONObject)webAppSession.launchSession.getRawData();
 else         newRawData=new JSONObject();
        try {
          newRawData.put(idKey,appId);
        }
 catch (        JSONException ex) {
          ex.printStackTrace();
        }
        webAppSession.launchSession.setRawData(newRawData);
      }
      if (connectionListener != null) {
        Util.runOnUI(new Runnable(){
          @Override public void run(){
            connectionListener.onSuccess(response);
          }
        }
);
      }
    }
    @Override public void onError(    ServiceCommandError error){
      ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.get(subscriptionKey);
      if (connectionSubscription != null) {
        if (!serviceDescription.getVersion().contains("String_Node_Str"))         connectionSubscription.unsubscribe();
        mAppToAppSubscriptions.remove(subscriptionKey);
        mAppToAppMessageListeners.remove(fullAppId);
      }
      boolean appChannelDidClose=false;
      if (error != null && error.getPayload() != null)       appChannelDidClose=error.getPayload().toString().contains("String_Node_Str");
      if (appChannelDidClose) {
        if (connectionSubscription != null)         connectionSubscription.unsubscribe();
        if (webAppSession != null && webAppSession.getWebAppSessionListener() != null) {
          Util.runOnUI(new Runnable(){
            @Override public void run(){
              webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
            }
          }
);
        }
      }
 else {
        Util.postError(connectionListener,error);
      }
    }
  }
;
  URLServiceSubscription<ResponseListener<Object>> subscription=new URLServiceSubscription<ResponseListener<Object>>(this,uri,payload,true,responseListener);
  subscription.subscribe();
  mAppToAppSubscriptions.put(subscriptionKey,subscription);
}

Fixed version (ground truth):
public void connectToWebApp(final WebOSWebAppSession webAppSession,final boolean joinOnly,final ResponseListener<Object> connectionListener){
  if (webAppSession == null || webAppSession.launchSession == null) {
    Util.postError(connectionListener,new ServiceCommandError(0,"String_Node_Str",null));
    return;
  }
  if (webAppSession.messageHandler == null) {
    Util.postError(connectionListener,new ServiceCommandError(-1,"String_Node_Str",null));
    return;
  }
  String _fullAppId=null;
  String _subscriptionKey=null;
  String _idKey=null;
  if (webAppSession.launchSession.getSessionType() == LaunchSession.LaunchSessionType.WebApp) {
    _fullAppId=String.format("String_Node_Str",webAppSession.launchSession.getAppId());
    _subscriptionKey=webAppSession.launchSession.getAppId();
    _idKey="String_Node_Str";
  }
 else   if (webAppSession.launchSession.getSessionType() == LaunchSession.LaunchSessionType.App) {
    _fullAppId=_subscriptionKey=webAppSession.launchSession.getAppId();
    _idKey="String_Node_Str";
  }
  if (_fullAppId == null || _fullAppId.length() == 0) {
    Util.postError(connectionListener,new ServiceCommandError(-1,"String_Node_Str",null));
    return;
  }
  URLServiceSubscription<ResponseListener<Object>> appToAppSubscription=(URLServiceSubscription<ResponseListener<Object>>)mAppToAppSubscriptions.get(_subscriptionKey);
  if (appToAppSubscription != null) {
    mAppToAppMessageListeners.put(_fullAppId,webAppSession.messageHandler);
    Util.postSuccess(connectionListener,webAppSession);
    return;
  }
  final String fullAppId=_fullAppId;
  final String subscriptionKey=_subscriptionKey;
  final String idKey=_idKey;
  String uri="String_Node_Str";
  JSONObject payload=new JSONObject();
  try {
    payload.put(idKey,subscriptionKey);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  ResponseListener<Object> responseListener=new ResponseListener<Object>(){
    @Override public void onSuccess(    final Object response){
      JSONObject jsonObj=(JSONObject)response;
      String state=jsonObj.optString("String_Node_Str");
      if (!state.equalsIgnoreCase("String_Node_Str")) {
        if (joinOnly && state.equalsIgnoreCase("String_Node_Str")) {
          Util.postError(connectionListener,new ServiceCommandError(0,"String_Node_Str",null));
        }
        return;
      }
      String appId=jsonObj.optString("String_Node_Str");
      if (appId != null && appId.length() != 0) {
        mAppToAppMessageListeners.put(appId,webAppSession.messageHandler);
        JSONObject newRawData;
        if (webAppSession.launchSession.getRawData() != null)         newRawData=(JSONObject)webAppSession.launchSession.getRawData();
 else         newRawData=new JSONObject();
        try {
          newRawData.put(idKey,appId);
        }
 catch (        JSONException ex) {
          ex.printStackTrace();
        }
        webAppSession.launchSession.setRawData(newRawData);
      }
      if (connectionListener != null) {
        Util.runOnUI(new Runnable(){
          @Override public void run(){
            connectionListener.onSuccess(response);
          }
        }
);
      }
    }
    @Override public void onError(    ServiceCommandError error){
      ServiceSubscription<ResponseListener<Object>> connectionSubscription=mAppToAppSubscriptions.get(subscriptionKey);
      if (connectionSubscription != null) {
        if (!serviceDescription.getVersion().contains("String_Node_Str"))         connectionSubscription.unsubscribe();
        mAppToAppSubscriptions.remove(subscriptionKey);
        mAppToAppMessageListeners.remove(fullAppId);
      }
      boolean appChannelDidClose=false;
      if (error != null && error.getPayload() != null)       appChannelDidClose=error.getPayload().toString().contains("String_Node_Str");
      if (appChannelDidClose) {
        if (connectionSubscription != null)         connectionSubscription.unsubscribe();
        if (webAppSession != null && webAppSession.getWebAppSessionListener() != null) {
          Util.runOnUI(new Runnable(){
            @Override public void run(){
              webAppSession.getWebAppSessionListener().onWebAppSessionDisconnect(webAppSession);
            }
          }
);
        }
      }
 else {
        Util.postError(connectionListener,error);
      }
    }
  }
;
  URLServiceSubscription<ResponseListener<Object>> subscription=new URLServiceSubscription<ResponseListener<Object>>(this,uri,payload,true,responseListener);
  subscription.subscribe();
  mAppToAppSubscriptions.put(subscriptionKey,subscription);
}