Program: 199348
Project: 199348
Buggy source:
private boolean handleNativeEvent(int code,String raw,String[] cooked){
  boolean handled=true;
  NsdServiceInfo servInfo;
  int id=Integer.parseInt(cooked[1]);
  ClientInfo clientInfo=mIdToClientInfoMap.get(id);
  if (clientInfo == null) {
    Slog.e(TAG,"String_Node_Str" + id);
    handled=false;
    return handled;
  }
  int clientId=-1;
  int keyId=clientInfo.mClientIds.indexOfValue(id);
  if (keyId != -1) {
    clientId=clientInfo.mClientIds.keyAt(keyId);
  }
 else {
    Slog.d(TAG,"String_Node_Str" + id);
    handled=false;
    return handled;
  }
switch (code) {
case NativeResponseCode.SERVICE_FOUND:
    if (DBG)     Slog.d(TAG,"String_Node_Str" + raw);
  servInfo=new NsdServiceInfo(cooked[2],cooked[3]);
clientInfo.mChannel.sendMessage(NsdManager.SERVICE_FOUND,0,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_LOST:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
servInfo=new NsdServiceInfo(cooked[2],cooked[3]);
clientInfo.mChannel.sendMessage(NsdManager.SERVICE_LOST,0,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_DISCOVERY_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.DISCOVER_SERVICES_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_REGISTERED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
servInfo=new NsdServiceInfo(cooked[2],null);
clientInfo.mChannel.sendMessage(NsdManager.REGISTER_SERVICE_SUCCEEDED,id,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_REGISTRATION_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.REGISTER_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_UPDATED:
break;
case NativeResponseCode.SERVICE_UPDATE_FAILED:
break;
case NativeResponseCode.SERVICE_RESOLVED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
int index=cooked[2].indexOf("String_Node_Str");
if (index == -1) {
Slog.e(TAG,"String_Node_Str" + raw);
break;
}
String name=cooked[2].substring(0,index);
String rest=cooked[2].substring(index);
String type=rest.replace("String_Node_Str","String_Node_Str");
clientInfo.mResolvedService.setServiceName(name);
clientInfo.mResolvedService.setServiceType(type);
clientInfo.mResolvedService.setPort(Integer.parseInt(cooked[4]));
stopResolveService(id);
removeRequestMap(clientId,id,clientInfo);
int id2=getUniqueId();
if (getAddrInfo(id2,cooked[3])) {
storeRequestMap(clientId,id2,clientInfo,NsdManager.RESOLVE_SERVICE);
}
 else {
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
clientInfo.mResolvedService=null;
}
break;
case NativeResponseCode.SERVICE_RESOLUTION_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
stopResolveService(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_GET_ADDR_FAILED:
stopGetAddrInfo(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_GET_ADDR_SUCCESS:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
try {
clientInfo.mResolvedService.setHost(InetAddress.getByName(cooked[4]));
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_SUCCEEDED,0,clientId,clientInfo.mResolvedService);
}
 catch (java.net.UnknownHostException e) {
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
}
stopGetAddrInfo(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
break;
default :
handled=false;
break;
}
return handled;
}

Fixed version (ground truth):
private boolean handleNativeEvent(int code,String raw,String[] cooked){
  boolean handled=true;
  NsdServiceInfo servInfo;
  int id=Integer.parseInt(cooked[1]);
  ClientInfo clientInfo=mIdToClientInfoMap.get(id);
  if (clientInfo == null) {
    Slog.e(TAG,"String_Node_Str" + id);
    handled=false;
    return handled;
  }
  int clientId=clientInfo.getClientId(id);
  if (clientId < 0) {
    Slog.d(TAG,"String_Node_Str" + id);
    handled=false;
    return handled;
  }
switch (code) {
case NativeResponseCode.SERVICE_FOUND:
    if (DBG)     Slog.d(TAG,"String_Node_Str" + raw);
  servInfo=new NsdServiceInfo(cooked[2],cooked[3]);
clientInfo.mChannel.sendMessage(NsdManager.SERVICE_FOUND,0,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_LOST:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
servInfo=new NsdServiceInfo(cooked[2],cooked[3]);
clientInfo.mChannel.sendMessage(NsdManager.SERVICE_LOST,0,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_DISCOVERY_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.DISCOVER_SERVICES_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_REGISTERED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
servInfo=new NsdServiceInfo(cooked[2],null);
clientInfo.mChannel.sendMessage(NsdManager.REGISTER_SERVICE_SUCCEEDED,id,clientId,servInfo);
break;
case NativeResponseCode.SERVICE_REGISTRATION_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.REGISTER_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_UPDATED:
break;
case NativeResponseCode.SERVICE_UPDATE_FAILED:
break;
case NativeResponseCode.SERVICE_RESOLVED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
int index=cooked[2].indexOf("String_Node_Str");
if (index == -1) {
Slog.e(TAG,"String_Node_Str" + raw);
break;
}
String name=cooked[2].substring(0,index);
String rest=cooked[2].substring(index);
String type=rest.replace("String_Node_Str","String_Node_Str");
clientInfo.mResolvedService.setServiceName(name);
clientInfo.mResolvedService.setServiceType(type);
clientInfo.mResolvedService.setPort(Integer.parseInt(cooked[4]));
stopResolveService(id);
removeRequestMap(clientId,id,clientInfo);
int id2=getUniqueId();
if (getAddrInfo(id2,cooked[3])) {
storeRequestMap(clientId,id2,clientInfo,NsdManager.RESOLVE_SERVICE);
}
 else {
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
clientInfo.mResolvedService=null;
}
break;
case NativeResponseCode.SERVICE_RESOLUTION_FAILED:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
stopResolveService(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_GET_ADDR_FAILED:
stopGetAddrInfo(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
break;
case NativeResponseCode.SERVICE_GET_ADDR_SUCCESS:
if (DBG) Slog.d(TAG,"String_Node_Str" + raw);
try {
clientInfo.mResolvedService.setHost(InetAddress.getByName(cooked[4]));
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_SUCCEEDED,0,clientId,clientInfo.mResolvedService);
}
 catch (java.net.UnknownHostException e) {
clientInfo.mChannel.sendMessage(NsdManager.RESOLVE_SERVICE_FAILED,NsdManager.FAILURE_INTERNAL_ERROR,clientId);
}
stopGetAddrInfo(id);
removeRequestMap(clientId,id,clientInfo);
clientInfo.mResolvedService=null;
break;
default :
handled=false;
break;
}
return handled;
}