nus-yam/ex-repair huggingface dataset:
Program: 179406
Project: 179406
Buggy source:
public void navigate(JsonElement element){
  if (element.isJsonArray()) {
    JsonArray array=element.getAsJsonArray();
    visitor.startArray(array);
    boolean isFirst=true;
    for (    JsonElement child : array) {
      visitChild(array,child,isFirst);
      if (isFirst) {
        isFirst=false;
      }
    }
    visitor.endArray(array);
  }
 else   if (element.isJsonObject()) {
    JsonObject object=element.getAsJsonObject();
    visitor.startObject(object);
    boolean isFirst=true;
    for (    Map.Entry<String,JsonElement> member : object.entrySet()) {
      visitChild(object,member.getKey(),member.getValue(),isFirst);
      if (isFirst) {
        isFirst=false;
      }
    }
    visitor.endObject(object);
  }
 else {
    visitor.visitPrimitive(element.getAsJsonPrimitive());
  }
}

Fixed version (ground truth):
public void navigate(JsonElement element){
  if (element == null) {
    visitor.visitNull();
  }
 else   if (element.isJsonArray()) {
    JsonArray array=element.getAsJsonArray();
    visitor.startArray(array);
    boolean isFirst=true;
    for (    JsonElement child : array) {
      visitChild(array,child,isFirst);
      if (isFirst) {
        isFirst=false;
      }
    }
    visitor.endArray(array);
  }
 else   if (element.isJsonObject()) {
    JsonObject object=element.getAsJsonObject();
    visitor.startObject(object);
    boolean isFirst=true;
    for (    Map.Entry<String,JsonElement> member : object.entrySet()) {
      visitChild(object,member.getKey(),member.getValue(),isFirst);
      if (isFirst) {
        isFirst=false;
      }
    }
    visitor.endObject(object);
  }
 else {
    visitor.visitPrimitive(element.getAsJsonPrimitive());
  }
}
Program: 179407
Project: 179407
Buggy source:
private void visitChild(JsonArray parent,JsonElement child,boolean isFirst){
  if (child.isJsonArray()) {
    JsonArray childAsArray=child.getAsJsonArray();
    visitor.visitArrayMember(parent,childAsArray,isFirst);
    navigate(childAsArray);
  }
 else   if (child.isJsonObject()) {
    JsonObject childAsObject=child.getAsJsonObject();
    visitor.visitArrayMember(parent,childAsObject,isFirst);
    navigate(childAsObject);
  }
 else {
    visitor.visitArrayMember(parent,child.getAsJsonPrimitive(),isFirst);
  }
}

Fixed version (ground truth):
private void visitChild(JsonArray parent,JsonElement child,boolean isFirst){
  if (child == null) {
    visitor.visitNullArrayMember(parent,isFirst);
    navigate(null);
  }
 else   if (child.isJsonArray()) {
    JsonArray childAsArray=child.getAsJsonArray();
    visitor.visitArrayMember(parent,childAsArray,isFirst);
    navigate(childAsArray);
  }
 else   if (child.isJsonObject()) {
    JsonObject childAsObject=child.getAsJsonObject();
    visitor.visitArrayMember(parent,childAsObject,isFirst);
    navigate(childAsObject);
  }
 else {
    visitor.visitArrayMember(parent,child.getAsJsonPrimitive(),isFirst);
  }
}
Program: 179408
Project: 179408
Buggy source:
public void testCollection(){
  Collection<Integer> target=Arrays.asList(1,2,3,4,5,6,7,8,9);
  assertEquals("String_Node_Str",gson.toJson(target));
}

Fixed version (ground truth):
public void testCollection(){
  Collection<Integer> target=Arrays.asList(1,2,3,4,5,6,7,8,9);
  Type targetType=new TypeToken<Collection<Integer>>(){
  }
.getType();
  String json=gson.toJson(target,targetType);
  assertEquals("String_Node_Str",json);
}
Program: 179409
Project: 179409
Buggy source:
/** 
 * This method is useful if you want custom deserialization corresponding to the specific generic type. For most other cases, use   {@link #fromJson(Class,String)} instead
 * @param < T > the type of the desired object
 * @param typeOfT the specific generic type of T
 * @param json the string from which the object is to be deserialized
 * @return an object of type T from the string
 * @throws ParseException if json is not a valid representation for an objectof type typeOfT.
 */
@SuppressWarnings("String_Node_Str") public <T>T fromJson(Type typeOfT,String json) throws ParseException {
  try {
    StringReader reader=new StringReader(json);
    JsonParser parser=new JsonParser(reader);
    JsonElement root=parser.parse();
    JsonDeserializer.Context context=new JsonDeserializationContext(navigatorFactory,deserializers,objectConstructor,typeAdapter);
    return context.deserialize(typeOfT,root);
  }
 catch (  TokenMgrError e) {
    throw new ParseException("String_Node_Str" + json + "String_Node_Str",e);
  }
catch (  com.google.gson.parser.ParseException e) {
    throw new ParseException("String_Node_Str" + json + "String_Node_Str",e);
  }
}

Fixed version (ground truth):
/** 
 * This method is useful if you want custom deserialization corresponding to the specific generic type. For most other cases, use   {@link #fromJson(Class,String)} instead
 * @param < T > the type of the desired object
 * @param typeOfT the specific generic type of T
 * @param json the string from which the object is to be deserialized
 * @return an object of type T from the string
 * @throws ParseException if json is not a valid representation for an objectof type typeOfT.
 */
@SuppressWarnings("String_Node_Str") public <T>T fromJson(Type typeOfT,String json) throws ParseException {
  try {
    StringReader reader=new StringReader(json);
    JsonParser parser=new JsonParser(reader);
    JsonElement root=parser.parse();
    JsonDeserializer.Context context=new JsonDeserializationContext(navigatorFactory,deserializers,objectConstructor,typeAdapter);
    return (T)context.deserialize(typeOfT,root);
  }
 catch (  TokenMgrError e) {
    throw new ParseException("String_Node_Str" + json + "String_Node_Str",e);
  }
catch (  com.google.gson.parser.ParseException e) {
    throw new ParseException("String_Node_Str" + json + "String_Node_Str",e);
  }
}
Program: 179410
Project: 179410
Buggy source:
@SuppressWarnings("String_Node_Str") public void visitCollection(@SuppressWarnings("String_Node_Str") Collection collection,Type collectionType){
  TypeInfo<Object> childTypeInfo=new TypeInfo<Object>(collectionType);
  Type childType=childTypeInfo.getGenericClass();
  for (  JsonElement jsonChild : json.getAsJsonArray()) {
    Object child=visitChild(childType,jsonChild);
    if (childType == Object.class && !ObjectNavigator.isPrimitive(child)) {
      throw new JsonParseException(collection + "String_Node_Str");
    }
    collection.add(child);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void visitCollection(@SuppressWarnings("String_Node_Str") Collection collection,Type collectionType){
  TypeInfo<Object> childTypeInfo=new TypeInfo<Object>(collectionType);
  Type childType=childTypeInfo.getGenericClass();
  for (  JsonElement jsonChild : json.getAsJsonArray()) {
    Object child=visitChild(childType,jsonChild);
    if (childType == Object.class && !ObjectNavigator.isPrimitiveOrString(child)) {
      throw new JsonParseException(collection + "String_Node_Str");
    }
    collection.add(child);
  }
}
Program: 179411
Project: 179411
Buggy source:
@SuppressWarnings("String_Node_Str") public void visitCollectionField(Field f,Object obj){
  try {
    JsonObject jsonObject=json.getAsJsonObject();
    String fName=f.getName();
    if (jsonObject.has(fName)) {
      Collection collection=(Collection)objectConstructor.construct(f.getType());
      f.set(obj,collection);
      Type childType=new TypeInfo(f.getGenericType()).getGenericClass();
      JsonArray jsonArray=jsonObject.get(fName).getAsJsonArray();
      for (      JsonElement jsonChild : jsonArray) {
        Object child=visitChild(childType,jsonChild);
        if (childType == Object.class && !ObjectNavigator.isPrimitive(child)) {
          throw new JsonParseException(fName + "String_Node_Str");
        }
        collection.add(child);
      }
    }
 else {
      f.set(obj,null);
    }
  }
 catch (  IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void visitCollectionField(Field f,Object obj){
  try {
    JsonObject jsonObject=json.getAsJsonObject();
    String fName=f.getName();
    if (jsonObject.has(fName)) {
      Collection collection=(Collection)objectConstructor.construct(f.getType());
      f.set(obj,collection);
      Type childType=new TypeInfo(f.getGenericType()).getGenericClass();
      JsonArray jsonArray=jsonObject.get(fName).getAsJsonArray();
      for (      JsonElement jsonChild : jsonArray) {
        Object child=visitChild(childType,jsonChild);
        if (childType == Object.class && !ObjectNavigator.isPrimitiveOrString(child)) {
          throw new JsonParseException(fName + "String_Node_Str");
        }
        collection.add(child);
      }
    }
 else {
      f.set(obj,null);
    }
  }
 catch (  IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
Program: 179412
Project: 179412
Buggy source:
public JsonPrimitive(Object primitive){
  if (primitive instanceof Character) {
    char c=((Character)primitive).charValue();
    this.value=String.valueOf(c);
  }
 else {
    Preconditions.checkArgument(primitive instanceof Number || primitive instanceof String || ObjectNavigator.isPrimitive(primitive));
    this.value=primitive;
  }
}

Fixed version (ground truth):
public JsonPrimitive(Object primitive){
  if (primitive instanceof Character) {
    char c=((Character)primitive).charValue();
    this.value=String.valueOf(c);
  }
 else {
    Preconditions.checkArgument(primitive instanceof Number || ObjectNavigator.isPrimitiveOrString(primitive));
    this.value=primitive;
  }
}
Program: 179413
Project: 179413
Buggy source:
/** 
 * Navigate all the fields of the specified object. If a field is null, it does not get visited.
 */
@SuppressWarnings("String_Node_Str") public void accept(Visitor visitor){
  if (obj == null) {
    return;
  }
  TypeInfo<?> objTypeInfo=new TypeInfo<Object>(objType);
  if (exclusionStrategy.shouldSkipClass(objTypeInfo.getTopLevelClass())) {
    return;
  }
  if (ancestors.contains(obj)) {
    throw new IllegalStateException("String_Node_Str" + obj);
  }
  ancestors.push(obj);
  try {
    if (isCollectionOrArray(objTypeInfo)) {
      if (objTypeInfo.isArray()) {
        visitor.visitArray(obj,objType);
      }
 else {
        visitor.visitCollection((Collection<?>)obj,objType);
      }
    }
 else     if (objTypeInfo.getTopLevelClass().isEnum()) {
      visitor.visitEnum(obj,objType);
    }
 else     if (objTypeInfo.isPrimitiveOrStringAndNotAnArray()) {
      visitor.visitPrimitiveValue(obj);
    }
 else     if (objType == Object.class && isPrimitive(obj)) {
      visitor.visitPrimitiveValue(obj);
    }
 else {
      if (!visitor.visitUsingCustomHandler(obj,objType)) {
        visitor.startVisitingObject(obj);
        for (Class<?> curr=objTypeInfo.getTopLevelClass(); curr != null && !curr.equals(Object.class); curr=curr.getSuperclass()) {
          if (!curr.isSynthetic()) {
            navigateClassFields(obj,curr,visitor);
          }
        }
        visitor.endVisitingObject(obj);
      }
    }
  }
  finally {
    ancestors.pop();
  }
}

Fixed version (ground truth):
/** 
 * Navigate all the fields of the specified object. If a field is null, it does not get visited.
 */
@SuppressWarnings("String_Node_Str") public void accept(Visitor visitor){
  if (obj == null) {
    return;
  }
  TypeInfo<?> objTypeInfo=new TypeInfo<Object>(objType);
  if (exclusionStrategy.shouldSkipClass(objTypeInfo.getTopLevelClass())) {
    return;
  }
  if (ancestors.contains(obj)) {
    throw new IllegalStateException("String_Node_Str" + obj);
  }
  ancestors.push(obj);
  try {
    if (isCollectionOrArray(objTypeInfo)) {
      if (objTypeInfo.isArray()) {
        visitor.visitArray(obj,objType);
      }
 else {
        visitor.visitCollection((Collection<?>)obj,objType);
      }
    }
 else     if (objTypeInfo.getTopLevelClass().isEnum()) {
      visitor.visitEnum(obj,objType);
    }
 else     if (objTypeInfo.isPrimitiveOrStringAndNotAnArray()) {
      visitor.visitPrimitiveValue(obj);
    }
 else     if (objType == Object.class && isPrimitiveOrString(obj)) {
      visitor.visitPrimitiveValue(obj);
    }
 else {
      if (!visitor.visitUsingCustomHandler(obj,objType)) {
        visitor.startVisitingObject(obj);
        for (Class<?> curr=objTypeInfo.getTopLevelClass(); curr != null && !curr.equals(Object.class); curr=curr.getSuperclass()) {
          if (!curr.isSynthetic()) {
            navigateClassFields(obj,curr,visitor);
          }
        }
        visitor.endVisitingObject(obj);
      }
    }
  }
  finally {
    ancestors.pop();
  }
}
Program: 179414
Project: 179414
Buggy source:
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.log);
  _fromPhoneNumber=getMyPhoneNumber();
  _textView=(TextView)findViewById(R.id.messageLog);
  _textView.setText(getString(R.string.welcome));
  loadPrefs();
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String logBasePath=prefs.getString("String_Node_Str",LOG_DEFAULT_PATH);
    _smsLogger=new SMSLogger(SMSLogger.MODE_SEND,logBasePath);
  }
 catch (  Exception e) {
    Toast.makeText(this,"String_Node_Str" + e.getMessage(),Toast.LENGTH_LONG).show();
  }
  _telMgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
}

Fixed version (ground truth):
/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.log);
  _fromPhoneNumber=getMyPhoneNumber();
  _textView=(TextView)findViewById(R.id.messageLog);
  _textView.setText(getString(R.string.welcome));
  loadPrefs();
  try {
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String logBasePath=prefs.getString("String_Node_Str",LOG_DEFAULT_PATH);
    _smsLogger=new SMSLogger(SMSLogger.MODE_SEND,logBasePath);
  }
 catch (  Exception e) {
    Toast.makeText(this,"String_Node_Str" + e.getMessage(),Toast.LENGTH_LONG).show();
  }
  _telMgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  _sentPI=PendingIntent.getBroadcast(this,0,new Intent(SENT),0);
  _deliveredPI=PendingIntent.getBroadcast(this,0,new Intent(DELIVERED),0);
}
Program: 179415
Project: 179415
Buggy source:
private void sendTestMessages(String toPhoneNumber,boolean useDataPort){
  _toPhoneNumber=toPhoneNumber;
  statusDialog=ProgressDialog.show(this,"String_Node_Str","String_Node_Str",true);
  statusDialog.setCancelable(true);
  statusDialog.show();
  listMsgs=loadTestMessageList();
  statusDialog.setMax(listMsgs.size());
  runThread=new Thread(this);
  runThread.start();
}

Fixed version (ground truth):
private void sendTestMessages(String toPhoneNumber,boolean useDataPort){
  _toPhoneNumber=toPhoneNumber;
  if (_statusRev != null)   unregisterReceiver(_statusRev);
  _statusRev=new SMSErrorStatusReceiver(_fromPhoneNumber,_toPhoneNumber,_smsLogger);
  registerReceiver(_statusRev,new IntentFilter(SENT));
  statusDialog=ProgressDialog.show(this,"String_Node_Str","String_Node_Str",true);
  statusDialog.setCancelable(true);
  statusDialog.show();
  listMsgs=loadTestMessageList();
  statusDialog.setMax(listMsgs.size());
  runThread=new Thread(this);
  runThread.start();
}
Program: 179416
Project: 179416
Buggy source:
public void run(){
  keepRunning=true;
  _smsLogger.logStart(operator,cid + "String_Node_Str",lac + "String_Node_Str",new Date());
  do {
    Iterator<String> itMsgs=listMsgs.iterator();
    int count=0;
    while (keepRunning && itMsgs.hasNext()) {
      String nextMsg=itMsgs.next();
      sendSMS(_toPhoneNumber,nextMsg,_useDataPort,_addTrackingMetadata);
      Message msg=new Message();
      Bundle data=new Bundle();
      data.putString("String_Node_Str","String_Node_Str" + nextMsg + "String_Node_Str");
      count++;
      data.putInt("String_Node_Str",count);
      msg.setData(data);
      handler.sendMessage(msg);
      try {
        Thread.sleep(_timeDelay);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
 while (_doLoop);
  Message msg=new Message();
  Bundle data=new Bundle();
  data.putInt("String_Node_Str",-1);
  msg.setData(data);
  handler.sendMessage(msg);
}

Fixed version (ground truth):
public void run(){
  keepRunning=true;
  do {
    Iterator<String> itMsgs=listMsgs.iterator();
    int count=0;
    while (keepRunning && itMsgs.hasNext()) {
      String nextMsg=itMsgs.next();
      sendSMS(_toPhoneNumber,nextMsg,_useDataPort,_addTrackingMetadata);
      Message msg=new Message();
      Bundle data=new Bundle();
      data.putString("String_Node_Str","String_Node_Str" + nextMsg + "String_Node_Str");
      count++;
      data.putInt("String_Node_Str",count);
      msg.setData(data);
      handler.sendMessage(msg);
      try {
        Thread.sleep(_timeDelay);
      }
 catch (      InterruptedException e) {
        Log.i(TAG,"String_Node_Str",e);
      }
    }
  }
 while (_doLoop);
  Message msg=new Message();
  Bundle data=new Bundle();
  data.putInt("String_Node_Str",-1);
  msg.setData(data);
  handler.sendMessage(msg);
}
Program: 179417
Project: 179417
Buggy source:
private void startSMSTest(){
  loadPrefs();
  getLocationInfo();
  _smsLogger.logStart(operator,cid + "String_Node_Str",lac + "String_Node_Str",new Date());
  AlertDialog.Builder alert=new AlertDialog.Builder(this);
  alert.setTitle("String_Node_Str");
  alert.setMessage("String_Node_Str");
  final EditText input=new EditText(this);
  if (_toPhoneNumber != null)   input.setText(_toPhoneNumber);
  alert.setView(input);
  alert.setPositiveButton("String_Node_Str",new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
      _toPhoneNumber=input.getText().toString();
      sendTestMessages(_toPhoneNumber,_useDataPort);
    }
  }
);
  alert.setNegativeButton("String_Node_Str",new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
    }
  }
);
  alert.show();
}

Fixed version (ground truth):
private void startSMSTest(){
  loadPrefs();
  AlertDialog.Builder alert=new AlertDialog.Builder(this);
  alert.setTitle("String_Node_Str");
  alert.setMessage("String_Node_Str");
  final EditText input=new EditText(this);
  if (_toPhoneNumber != null)   input.setText(_toPhoneNumber);
  alert.setView(input);
  alert.setPositiveButton("String_Node_Str",new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
      _toPhoneNumber=input.getText().toString();
      sendTestMessages(_toPhoneNumber,_useDataPort);
    }
  }
);
  alert.setNegativeButton("String_Node_Str",new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
    }
  }
);
  alert.show();
}
Program: 179418
Project: 179418
Buggy source:
private void sendSMS(String phoneNumber,String testMessage,boolean useDataPort,boolean addTrackingMetadata){
  PendingIntent sentPI=PendingIntent.getBroadcast(this,0,new Intent(SENT),0);
  PendingIntent deliveredPI=PendingIntent.getBroadcast(this,0,new Intent(DELIVERED),0);
  getLocationInfo();
  StringBuffer message=new StringBuffer();
  message.append(testMessage);
  if (addTrackingMetadata) {
    message.append(' ');
    message.append("String_Node_Str");
    message.append(java.util.UUID.randomUUID().toString());
    message.append(' ');
    message.append("String_Node_Str");
    message.append(new Date().getTime());
    message.append(' ');
    message.append("String_Node_Str");
    message.append(cid);
    message.append(' ');
    message.append("String_Node_Str");
    message.append(lac);
  }
  SMSSentStatusReceiver statusRev=new SMSSentStatusReceiver(_fromPhoneNumber,phoneNumber,message.toString(),operator,cid + "String_Node_Str",lac + "String_Node_Str",_smsLogger);
  registerReceiver(statusRev,new IntentFilter(SENT));
  if (!useDataPort) {
    sms.sendTextMessage(phoneNumber,null,message.toString(),sentPI,deliveredPI);
  }
 else {
    sms.sendDataMessage(phoneNumber,null,SMS_DATA_PORT,message.toString().getBytes(),sentPI,deliveredPI);
  }
}

Fixed version (ground truth):
private void sendSMS(String phoneNumber,String testMessage,boolean useDataPort,boolean addTrackingMetadata){
  String operator;
  int cid=-1, lac=-1;
  CellLocation location=(CellLocation)_telMgr.getCellLocation();
  if (location instanceof GsmCellLocation) {
    cid=((GsmCellLocation)location).getCid();
    lac=((GsmCellLocation)location).getLac();
  }
  operator=_telMgr.getNetworkOperator();
  StringBuffer message=new StringBuffer();
  message.append(testMessage);
  if (addTrackingMetadata) {
    String shortUUID=java.util.UUID.randomUUID().toString();
    shortUUID=shortUUID.substring(0,8);
    message.append(' ');
    message.append("String_Node_Str");
    message.append(shortUUID);
    message.append(' ');
    message.append("String_Node_Str");
    message.append(new Date().getTime());
    message.append(' ');
    message.append("String_Node_Str");
    message.append(cid);
    message.append(' ');
    message.append("String_Node_Str");
    message.append(lac);
    message.append(' ');
    message.append("String_Node_Str");
    message.append(operator);
  }
  if (!useDataPort) {
    sms.sendTextMessage(phoneNumber,null,message.toString(),_sentPI,_deliveredPI);
  }
 else {
    sms.sendDataMessage(phoneNumber,null,SMS_DATA_PORT,message.toString().getBytes(),_sentPI,_deliveredPI);
  }
  _smsLogger.logSend(_fromPhoneNumber,_toPhoneNumber,message.toString(),new Date(),operator,cid + "String_Node_Str",lac + "String_Node_Str");
}
Program: 179419
Project: 179419
Buggy source:
private void stopSMSTest(){
  _doLoop=false;
  keepRunning=false;
}

Fixed version (ground truth):
private void stopSMSTest(){
  _doLoop=false;
  keepRunning=false;
  if (runThread.isAlive())   runThread.interrupt();
}
Program: 179420
Project: 179420
Buggy source:
public static <T>PropertyInfo<T> createPropertyInfo(String name,Class<T> valueType){
  return new PropertyInfo<T>(name){
  }
;
}

Fixed version (ground truth):
public static <T>PropertyInfo<T> createPropertyInfo(String name,Class<T> valueType){
  return new PropertyInfo<T>(name,valueType){
  }
;
}
Program: 179421
Project: 179421
Buggy source:
@SuppressWarnings("String_Node_Str") private PropertyInfo(String name){
  this.name=name;
  valueType=(Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}

Fixed version (ground truth):
private PropertyInfo(String name,Class<T> valueType){
  this.name=name;
  this.valueType=valueType;
}
Program: 179422
Project: 179422
Buggy source:
public void setValue(T value){
  internalSetValue(value);
}

Fixed version (ground truth):
public void setValue(T value){
  internalSetValue(value);
  notifyListeners();
}
Program: 179423
Project: 179423
Buggy source:
/** 
 * Forward quotes to specific day (only day/month/year are being taken into account). Please ensure given date is a working day! In other case iterator will be set to point end of the quotes stream.
 * @param date - date to find (<b>must</b> be working day)
 */
public void forward(Date date){
  if (hasNext()) {
    long a=next.getDate().getTime();
    long b=date.getTime();
    long m=1000 * 60 * 60* 24;
    if (b / m < (a - m) / m) {
      SimpleDateFormat sdf=new SimpleDateFormat("String_Node_Str");
      throw new IllegalArgumentException("String_Node_Str" + sdf.format(next.getDate()) + "String_Node_Str"+ "String_Node_Str"+ sdf.format(date));
    }
  }
 else {
    throw new NoSuchElementException("String_Node_Str");
  }
  boolean found=false;
  try {
    found=qsr.seek(date);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (found) {
    next=null;
  }
}

Fixed version (ground truth):
/** 
 * Forward quotes to specific day (only day/month/year are being taken into account). Please ensure given date is a working day! In other case iterator will be set to point end of the quotes stream.
 * @param date - date to find (<b>must</b> be working day)
 */
public void forward(Date date){
  if (hasNext()) {
    long a=next.getDate().getTime();
    long b=date.getTime();
    long m=1000 * 60 * 60* 24;
    long db=b / m;
    long da=(a - m) / m;
    if (db < da) {
      SimpleDateFormat sdf=new SimpleDateFormat("String_Node_Str");
      throw new IllegalArgumentException("String_Node_Str" + sdf.format(next.getDate()) + "String_Node_Str"+ "String_Node_Str"+ sdf.format(date));
    }
 else     if (db == da) {
      return;
    }
 else {
      boolean found=false;
      try {
        found=qsr.seek(date);
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
      if (found) {
        next=null;
      }
    }
  }
 else {
    throw new NoSuchElementException("String_Node_Str");
  }
}
Program: 179424
Project: 179424
Buggy source:
public static Date fromCGL(String str){
  SimpleDateFormat sdf=new SimpleDateFormat("String_Node_Str");
  try {
    return sdf.parse(str);
  }
 catch (  ParseException e) {
    throw new RuntimeException("String_Node_Str" + str,e);
  }
}

Fixed version (ground truth):
public static Date fromCGL(String str){
  SimpleDateFormat sdf=QuotesStreamReader.DATE_FORMAT_SHORT;
  try {
    return sdf.parse(str);
  }
 catch (  ParseException e) {
    throw new RuntimeException("String_Node_Str" + str,e);
  }
}
Program: 179425
Project: 179425
Buggy source:
@Override public QuotesIterator<Quote> getIntradayQuotes(Symbol symbol) throws ProviderException {
  String tmpdir=CFG.getProperty("String_Node_Str","String_Node_Str");
  File f=new File(tmpdir + "String_Node_Str" + symbol.getName()+ "String_Node_Str");
  InputStream is=null;
  try {
    is=FileUtils.openInputStream(f);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return new QuotesIterator<Quote>(is);
}

Fixed version (ground truth):
@Override public QuotesIterator<Quote> getIntradayQuotes(Symbol symbol) throws ProviderException {
  String tmpdir=CFG.getProperty("String_Node_Str","String_Node_Str");
  File f=new File(tmpdir + "String_Node_Str" + symbol.getName()+ "String_Node_Str");
  if (!f.exists()) {
    throw new ProviderException("String_Node_Str" + f.getPath());
  }
  InputStream is=null;
  try {
    is=FileUtils.openInputStream(f);
  }
 catch (  IOException e) {
    throw new ProviderException("String_Node_Str" + f.getPath());
  }
  return new QuotesIterator<Quote>(is);
}
Program: 179426
Project: 179426
Buggy source:
public FakeRealTimeProvider(Symbol symbol,long from,long to){
  if (from > to) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + from + "String_Node_Str"+ to);
  }
  try {
    qi=new QuotesIterator<Quote>(symbol);
  }
 catch (  FileNotFoundException e) {
    try {
      qi=Providers.getHistoryProvider().getIntradayQuotes(symbol);
    }
 catch (    ProviderException e1) {
      e1.printStackTrace();
    }
  }
catch (  IOException e) {
    throw new RuntimeException(e);
  }
  this.from=from;
  this.to=to;
  this.registry=FakeQuotesRegistry.getInstance();
}

Fixed version (ground truth):
public FakeRealTimeProvider(Symbol symbol,Date from,Date to){
  if (from != null) {
    this.from=from.getTime();
  }
 else {
    this.from=Long.MIN_VALUE;
  }
  if (to != null) {
    this.to=to.getTime();
  }
 else {
    this.to=Long.MAX_VALUE;
  }
  if (this.from > this.to) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + from + "String_Node_Str"+ to);
  }
  try {
    qi=new QuotesIterator<Quote>(symbol);
  }
 catch (  FileNotFoundException e) {
    try {
      qi=Providers.getHistoryProvider().getIntradayQuotes(symbol);
    }
 catch (    ProviderException e1) {
      e1.printStackTrace();
    }
  }
catch (  IOException e) {
    throw new RuntimeException(e);
  }
  if (from != null) {
    qi.forward(from);
    if (!qi.hasNext()) {
      throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + from + "String_Node_Str"+ to);
    }
  }
  this.registry=FakeQuotesRegistry.getInstance();
}
Program: 179427
Project: 179427
Buggy source:
@Override public Quote getQuote(Symbol symbol) throws ProviderException {
  if (reached) {
    return null;
  }
  Date d=null;
  Quote q=null;
  do {
    if ((q=qi.next()) == null) {
      return null;
    }
    putInRegistry(symbol,q);
    d=q.getDate();
  }
 while (d.getTime() < from);
  if (d.getTime() > to) {
    reached=true;
  }
  if (last != null) {
    q.setOpen(open);
    q.setHigh(high);
    q.setLow(low);
    q.setVolume(volume);
  }
  return q;
}

Fixed version (ground truth):
@Override public Quote getQuote(Symbol symbol) throws ProviderException {
  if (reached) {
    return null;
  }
  Date d=null;
  Quote q=null;
  do {
    try {
      q=qi.next();
    }
 catch (    NoSuchElementException e) {
      this.reached=true;
      qi.close();
      return null;
    }
    putInRegistry(symbol,q);
    d=q.getDate();
  }
 while (d.getTime() < from);
  if (d.getTime() > to) {
    reached=true;
    qi.close();
    return null;
  }
  if (last != null) {
    q.setOpen(open);
    q.setHigh(high);
    q.setLow(low);
    q.setVolume(volume);
  }
  return q;
}
Program: 179428
Project: 179428
Buggy source:
public static void main(String[] args) throws InterruptedException {
  Configuration CFG=Configuration.getInstance();
  CFG.setProperty("String_Node_Str","String_Node_Str","String_Node_Str");
  CFG.setProperty("String_Node_Str","String_Node_Str","String_Node_Str");
  Symbol symbol=Symbol.FW20M11;
  String name=symbol + "String_Node_Str";
  SignalGenerator<Quote> siggen=new MAVD(5,10,20);
  Paper paper=new Paper(symbol);
  RealTimeProvider provider=new FakeRealTimeProvider(symbol,1,2);
  final FuturesTrader trader=new FuturesTrader(name,siggen,paper,provider);
  trader.getObserver().setInterval(0);
  trader.getDecisionMaker().setNullHandler(new NullEventHandler(){
    @Override public void handleNull(    NullEvent ne){
      trader.getObserver().stop();
    }
  }
);
  trader.trade();
  Thread.sleep(20000);
}

Fixed version (ground truth):
public static void main(String[] args) throws InterruptedException {
  Configuration CFG=Configuration.getInstance();
  CFG.setProperty("String_Node_Str","String_Node_Str","String_Node_Str");
  CFG.setProperty("String_Node_Str","String_Node_Str","String_Node_Str");
  Symbol symbol=Symbol.FW20M11;
  String name=symbol + "String_Node_Str";
  SignalGenerator<Quote> siggen=new MAVD(5,10,20);
  Paper paper=new Paper(symbol);
  RealTimeProvider provider=new FakeRealTimeProvider(symbol,null,null);
  final FuturesTrader trader=new FuturesTrader(name,siggen,paper,provider);
  trader.getObserver().setInterval(0);
  trader.getDecisionMaker().setNullHandler(new NullEventHandler(){
    @Override public void handleNull(    NullEvent ne){
      trader.getObserver().stop();
    }
  }
);
  trader.trade();
  Thread.sleep(20000);
}
Program: 179429
Project: 179429
Buggy source:
@Test public void test_getQuote() throws ProviderException {
  FakeRealTimeProvider sp=new FakeRealTimeProvider(SYMBOL,start.getTime(),end.getTime());
  while (!sp.isReached()) {
    Quote q=sp.getQuote(SYMBOL);
    System.out.println(q);
  }
}

Fixed version (ground truth):
@Test public void test_getQuote() throws ProviderException {
  Date start=DateUtils.fromCGL("String_Node_Str");
  Date end=DateUtils.fromCGL("String_Node_Str");
  FakeRealTimeProvider sp=new FakeRealTimeProvider(SYMBOL,start,end);
  for (int i=0; !sp.isReached(); i++) {
    Quote q=sp.getQuote(SYMBOL);
    if (i < 5) {
      Assert.assertNotNull(q);
    }
 else {
      Assert.assertNull(q);
    }
  }
}
Program: 179430
Project: 179430
Buggy source:
private DBDAO() throws DBDAOException {
  String usr=cfg.getProperty("String_Node_Str","String_Node_Str");
  String pwd=cfg.getProperty("String_Node_Str","String_Node_Str");
  try {
    con=DriverManager.getConnection(url,usr,pwd);
    SQLUtils.installProcedures(con);
  }
 catch (  Exception e) {
    throw new DBDAOException(e);
  }
}

Fixed version (ground truth):
private DBDAO() throws DBDAOException {
  String usr=cfg.getProperty("String_Node_Str","String_Node_Str");
  String pwd=cfg.getProperty("String_Node_Str","String_Node_Str");
  if (usr == null) {
    throw new DBDAOException("String_Node_Str");
  }
  if (pwd == null) {
    throw new DBDAOException("String_Node_Str");
  }
  try {
    con=DriverManager.getConnection(url,usr,pwd);
    SQLUtils.installProcedures(con);
  }
 catch (  Exception e) {
    throw new DBDAOException(e);
  }
}
Program: 179431
Project: 179431
Buggy source:
/** 
 * Install all stored procedures from the Medusa stored procedures directory.
 * @throws SQLException if stored procedures directory is empty or otherreason
 */
public static void installProcedures(Connection conn) throws SQLException {
  File dir=new File(STORED_PROC_PATH);
  String[] paths=dir.list(new SQLFileFilter());
  if (paths.length > 0) {
    String name=null;
    for (    String path : paths) {
      name=path.substring(0,path.lastIndexOf("String_Node_Str"));
      try {
        installProcedure(conn,name);
      }
 catch (      IOException e) {
        LOG.error(e.getMessage(),e);
      }
    }
  }
 else {
    throw new SQLException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Install all stored procedures from the Medusa stored procedures directory.
 * @throws SQLException if stored procedures directory is empty or otherreason
 */
public static void installProcedures(Connection conn) throws SQLException {
  if (STORED_PROC_PATH == null) {
    throw new RuntimeException("String_Node_Str");
  }
  File dir=new File(STORED_PROC_PATH);
  String[] paths=dir.list(new SQLFileFilter());
  if (paths.length > 0) {
    String name=null;
    for (    String path : paths) {
      name=path.substring(0,path.lastIndexOf("String_Node_Str"));
      try {
        installProcedure(conn,name);
      }
 catch (      IOException e) {
        LOG.error(e.getMessage(),e);
      }
    }
  }
 else {
    throw new SQLException("String_Node_Str");
  }
}
Program: 179432
Project: 179432
Buggy source:
public static void main(String[] args){
  List<Double> list=new LinkedList<Double>();
  for (int u=0; u < close.length; u++) {
    list.add(close[u]);
  }
  Collections.reverse(list);
  for (int u=0; u < list.size(); u++) {
    close[u]=list.get(u);
  }
  double[] jma=SX.reverse(jrk(close,3,5));
  for (int i=70; i < jma.length; i++) {
    System.out.println(Double.toString(jma[i]).replaceAll("String_Node_Str","String_Node_Str") + "String_Node_Str");
  }
}

Fixed version (ground truth):
public static void main(String[] args){
  List<Double> list=new LinkedList<Double>();
  for (int u=0; u < close.length; u++) {
    list.add(close[u]);
  }
  Collections.reverse(list);
  for (int u=0; u < list.size(); u++) {
    close[u]=list.get(u);
  }
  double[] jma=SX.reverse(jrk(close,5,0));
  for (int i=70; i < jma.length; i++) {
    System.out.println(jma[i] - ref[i]);
  }
}
Program: 179433
Project: 179433
Buggy source:
/** 
 * Calculate <b>J</b>urik's <b>M</b>oving <b>A</b>verage for given quote point.
 * @param q - quote
 * @param K - MA degree
 * @param P - phase
 * @return Return double value
 */
public static double jma(Quote q,double K,double P){
  double[] c=SX.reverse(SX.detach(q,80)[3]);
  double[] jma=JRK.jrk(c,K,P);
  return jma[jma.length - 1];
}

Fixed version (ground truth):
/** 
 * Calculate <b>J</b>urik's <b>M</b>oving <b>A</b>verage for given quote point.
 * @param q - quote
 * @param K - MA degree
 * @param P - phase
 * @return Return double value
 */
public static double jma(Quote q,double K,double P){
  double[] c=SX.reverse(SX.detach(q,100)[3]);
  double[] jma=JRK.jrk(c,K,P);
  return jma[0];
}
Program: 179434
Project: 179434
Buggy source:
/** 
 * @return Return instance of history data provider
 */
public HistoryProvider getProvider(){
  String tmp=CFG.getProperty("String_Node_Str","String_Node_Str");
  if (name == null || !name.equals(tmp)) {
    name=tmp;
    Class<?> clazz=null;
    try {
      clazz=Class.forName(name);
    }
 catch (    ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
    if (!HistoryProvider.class.isAssignableFrom(clazz)) {
      throw new RuntimeException("String_Node_Str" + HistoryProvider.class.getSimpleName());
    }
    Class<? extends HistoryProvider> pclazz=clazz.asSubclass(HistoryProvider.class);
    try {
      provider=pclazz.newInstance();
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  return provider;
}

Fixed version (ground truth):
/** 
 * @return Return instance of history data provider
 */
public HistoryProvider getProvider(){
  String tmp=CFG.getProperty("String_Node_Str","String_Node_Str");
  if (tmp == null) {
    return null;
  }
  if (name == null || !name.equals(tmp)) {
    name=tmp;
    Class<?> clazz=null;
    try {
      clazz=Class.forName(name);
    }
 catch (    ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
    if (!HistoryProvider.class.isAssignableFrom(clazz)) {
      throw new RuntimeException("String_Node_Str" + HistoryProvider.class.getSimpleName());
    }
    Class<? extends HistoryProvider> pclazz=clazz.asSubclass(HistoryProvider.class);
    try {
      provider=pclazz.newInstance();
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  return provider;
}
Program: 179436
Project: 179436
Buggy source:
private void downloadZIP(File zipf,Symbol symbol) throws ProviderException {
  FileOutputStream fos=null;
  HttpEntity entity=null;
  try {
    fos=new FileOutputStream(zipf);
    MedusaHttpClient client=new MedusaHttpClient();
    HttpGet get=new HttpGet("String_Node_Str" + symbol.getName() + "String_Node_Str");
    HttpResponse response=client.execute(get);
    entity=response.getEntity();
    entity.writeTo(fos);
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str" + symbol + "String_Node_Str");
    }
  }
 catch (  Exception e) {
    throw new ProviderException(e);
  }
 finally {
    if (fos != null) {
      try {
        fos.close();
      }
 catch (      IOException e) {
        throw new ProviderException(e);
      }
    }
    if (entity != null) {
      try {
        entity.getContent().close();
      }
 catch (      Exception e) {
        throw new ProviderException(e);
      }
    }
  }
}

Fixed version (ground truth):
private void downloadZIP(File zipf,Symbol symbol) throws ProviderException {
  FileOutputStream fos=null;
  HttpEntity entity=null;
  try {
    if (!zipf.exists()) {
      File parent=new File(zipf.getParent());
      if (!parent.exists()) {
        parent.mkdirs();
      }
      if (!zipf.exists()) {
        if (zipf.createNewFile()) {
          throw new ProviderException("String_Node_Str");
        }
      }
    }
    fos=new FileOutputStream(zipf);
    MedusaHttpClient client=new MedusaHttpClient();
    HttpGet get=new HttpGet("String_Node_Str" + symbol.getName() + "String_Node_Str");
    HttpResponse response=client.execute(get);
    entity=response.getEntity();
    entity.writeTo(fos);
    if (LOG.isDebugEnabled()) {
      LOG.debug("String_Node_Str" + symbol + "String_Node_Str");
    }
  }
 catch (  Exception e) {
    throw new ProviderException(e);
  }
 finally {
    if (fos != null) {
      try {
        fos.close();
      }
 catch (      IOException e) {
        throw new ProviderException(e);
      }
    }
    if (entity != null) {
      try {
        entity.getContent().close();
      }
 catch (      Exception e) {
        throw new ProviderException(e);
      }
    }
  }
}
Program: 179439
Project: 179439
Buggy source:
@Override public void priceChange(PriceEvent pe){
  if (pe instanceof NullEvent) {
    handleNull((NullEvent)pe);
    return;
  }
  Paper paper=null;
  if (trader != null) {
    paper=trader.getPaper();
  }
 else {
    paper=Wallet.getInstance().getPaper(observer.getSymbol());
  }
  if (paper == null) {
    throw new RuntimeException("String_Node_Str" + "String_Node_Str" + trader.getSymbol());
  }
  Quote quote=pe.getQuote();
  Symbol symbol=observer.getSymbol();
  quote=bind(quote,symbol);
  Signal signal=generator.generate(quote);
  SignalType type=signal.getType();
  boolean buy=position == SHORT && type == BUY;
  boolean sell=position == LONG && type == SELL;
  if (LOG.isInfoEnabled()) {
    LOG.info("String_Node_Str" + pe + "String_Node_Str"+ signal);
  }
  if (buy || sell) {
    notifyListeners(new DecisionEvent(this,paper,quote,type));
  }
 else {
    unbind(quote,symbol);
  }
}

Fixed version (ground truth):
@Override public void priceChange(PriceEvent pe){
  if (pe instanceof NullEvent) {
    handleNull((NullEvent)pe);
    return;
  }
  Paper paper=null;
  if (trader != null) {
    paper=trader.getPaper();
  }
 else {
    paper=Wallet.getInstance().getPaper(observer.getSymbol());
  }
  if (paper == null) {
    throw new RuntimeException("String_Node_Str" + "String_Node_Str" + observer.getSymbol());
  }
  Quote quote=pe.getQuote();
  Symbol symbol=observer.getSymbol();
  quote=bind(quote,symbol);
  Signal signal=generator.generate(quote);
  SignalType type=signal.getType();
  boolean buy=position == SHORT && type == BUY;
  boolean sell=position == LONG && type == SELL;
  if (LOG.isInfoEnabled()) {
    LOG.info("String_Node_Str" + pe + "String_Node_Str"+ signal);
  }
  if (buy || sell) {
    notifyListeners(new DecisionEvent(this,paper,quote,type));
  }
 else {
    unbind(quote,symbol);
  }
}
Program: 179440
Project: 179440
Buggy source:
/** 
 * Force reload wallet from the database.
 */
public void reload(){
  papers=dbdao.getPapers();
}

Fixed version (ground truth):
/** 
 * Force reload wallet from the database.
 */
public void reload(){
  if (dbdao == null) {
    throw new RuntimeException("String_Node_Str");
  }
  papers=dbdao.getPapers();
}
Program: 179443
Project: 179443
Buggy source:
@Override public void priceChange(PriceEvent pe){
  if (pe instanceof NullEvent) {
    handleNull((NullEvent)pe);
    return;
  }
  Paper paper=null;
  if (trader == null) {
    paper=trader.getPaper();
  }
 else {
    paper=Wallet.getInstance().getPaper(observer.getSymbol());
  }
  if (paper == null) {
    throw new RuntimeException("String_Node_Str");
  }
  Quote quote=pe.getQuote();
  Symbol symbol=observer.getSymbol();
  quote=bind(quote,symbol);
  Signal signal=generator.generate(quote);
  SignalType type=signal.getType();
  boolean buy=position == SHORT && type == BUY;
  boolean sell=position == LONG && type == SELL;
  if (LOG.isInfoEnabled()) {
    LOG.info("String_Node_Str" + pe + "String_Node_Str"+ signal);
  }
  if (buy || sell) {
    notifyListeners(new DecisionEvent(this,paper,quote,type));
  }
 else {
    unbind(quote,symbol);
  }
}

Fixed version (ground truth):
@Override public void priceChange(PriceEvent pe){
  if (pe instanceof NullEvent) {
    handleNull((NullEvent)pe);
    return;
  }
  Paper paper=null;
  if (trader == null) {
    paper=trader.getPaper();
  }
 else {
    paper=Wallet.getInstance().getPaper(observer.getSymbol());
  }
  if (paper == null) {
    throw new RuntimeException("String_Node_Str" + "String_Node_Str" + trader.getSymbol());
  }
  Quote quote=pe.getQuote();
  Symbol symbol=observer.getSymbol();
  quote=bind(quote,symbol);
  Signal signal=generator.generate(quote);
  SignalType type=signal.getType();
  boolean buy=position == SHORT && type == BUY;
  boolean sell=position == LONG && type == SELL;
  if (LOG.isInfoEnabled()) {
    LOG.info("String_Node_Str" + pe + "String_Node_Str"+ signal);
  }
  if (buy || sell) {
    notifyListeners(new DecisionEvent(this,paper,quote,type));
  }
 else {
    unbind(quote,symbol);
  }
}
Program: 179444
Project: 179444
Buggy source:
/** 
 * Run once per observer tick. If price is different in comparison previous one, notify price listeners.
 * @throws ProviderException
 */
protected void runOnce() throws ProviderException {
  Quote q=provider.getQuote(symbol);
  if (q == null) {
    notifyListeners(new NullEvent(this,price,price,null));
  }
 else {
    double tmp=q.getClose();
    if (tmp != price && price != -1) {
      notifyListeners(new PriceEvent(this,price,tmp,q));
    }
    price=tmp;
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug(getSymbol() + "String_Node_Str" + q);
  }
}

Fixed version (ground truth):
/** 
 * Run once per observer tick. If price is different in comparison previous one, notify price listeners.
 * @throws ProviderException
 */
protected void runOnce() throws ProviderException {
  Quote q=null;
  try {
    q=provider.getQuote(symbol);
  }
 catch (  QuoteLackException e) {
    LOG.warn(e.getMessage());
    return;
  }
  if (q == null) {
    notifyListeners(new NullEvent(this,price,price,null));
  }
 else {
    double tmp=q.getClose();
    if (tmp != price && price != -1) {
      notifyListeners(new PriceEvent(this,price,tmp,q));
    }
    price=tmp;
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug(getSymbol() + "String_Node_Str" + q);
  }
}
Program: 179445
Project: 179445
Buggy source:
/** 
 * @return Return paper.
 */
public Paper getPaper(){
  return paper;
}

Fixed version (ground truth):
/** 
 * @return Return paper.
 */
public Paper getPaper(){
  if (paper == null) {
    paper=new Paper(getSymbol(),paperDesiredQuantity,paperQuantity);
  }
  return paper;
}
Program: 179446
Project: 179446
Buggy source:
/** 
 * Obtain message for particular message code.
 * @param code - code to search
 * @return Message for given code or null if message has not been found
 * @throws SmesXException
 */
public Message receiveSMSForCode(String code) throws SmesXException {
  if (code == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  SmesXSMSReceive receiveSMS=null;
  do {
    receiveSMS=new SmesXSMSReceive();
    receiveSMS.setMarkAsRead(false);
    receiveSMS.setType(UNREAD);
    SmesXResponse response=execute(receiveSMS);
    SmesXOperation operation=response.getOperation();
    if (operation instanceof SmesXSMSReceive) {
      receiveSMS=(SmesXSMSReceive)operation;
      if (receiveSMS.containSMS()) {
        SmesXSMS sms=receiveSMS.getSMS();
        Message message=smsToMessage(sms);
        if (code.equals(message.getCode())) {
          return message;
        }
        if (receiveSMS.hasMore()) {
          receiveSMS.setAfterID(sms.getId());
        }
      }
    }
  }
 while (receiveSMS.hasMore());
  return null;
}

Fixed version (ground truth):
/** 
 * Obtain message for particular message code.
 * @param code - code to search
 * @return Message for given code or null if message has not been found
 * @throws SmesXException
 */
public Message receiveSMSForCode(String code) throws SmesXException {
  return smsToMessage(receiveRawSMSForCode(code));
}