Program: 154776
Project: 154776
Buggy source:
static XaCommand readCommand(ReadableByteChannel channel,ByteBuffer buffer,LuceneDataSource dataSource) throws IOException {
  buffer.clear();
  buffer.limit(1);
  if (channel.read(buffer) != buffer.limit()) {
    return null;
  }
  buffer.flip();
  byte commandType=buffer.get();
  if (commandType == CREATE_INDEX_COMMAND) {
    buffer.clear();
    String name=PrimitiveUtils.readLengthAndString(channel,buffer);
    if (name == null) {
      return null;
    }
    int size=PrimitiveUtils.readInt(channel,buffer);
    Map<String,String> config=new HashMap<String,String>();
    for (int i=0; i < size; i++) {
      String key=PrimitiveUtils.readLengthAndString(channel,buffer);
      String value=PrimitiveUtils.readLengthAndString(channel,buffer);
      if (key == null || value == null) {
        return null;
      }
      config.put(key,value);
    }
    return new CreateIndexCommand(name,config);
  }
 else {
    buffer.clear();
    buffer.limit(18);
    if (channel.read(buffer) != buffer.limit()) {
      return null;
    }
    buffer.flip();
    byte cls=buffer.get();
    EntityType entityType=null;
    if (cls == NODE) {
      entityType=dataSource.nodeEntityType;
    }
 else     if (cls == RELATIONSHIP) {
      entityType=dataSource.relationshipEntityType;
    }
 else {
      return null;
    }
    int indexNameLength=buffer.getInt();
    long entityId=buffer.getLong();
    int keyCharLength=buffer.getInt();
    byte valueType=buffer.get();
    String indexName=PrimitiveUtils.readString(channel,buffer,indexNameLength);
    if (indexName == null) {
      return null;
    }
    String key=PrimitiveUtils.readString(channel,buffer,keyCharLength);
    if (key == null) {
      return null;
    }
    Object value=null;
    if (valueType >= VALUE_TYPE_INT && valueType <= VALUE_TYPE_DOUBLE) {
switch (valueType) {
case VALUE_TYPE_INT:
        value=buffer.getInt();
      break;
case VALUE_TYPE_LONG:
    value=buffer.getLong();
  break;
case VALUE_TYPE_FLOAT:
value=buffer.getFloat();
break;
case VALUE_TYPE_DOUBLE:
value=buffer.getDouble();
break;
}
}
 else if (valueType == VALUE_TYPE_STRING) {
value=PrimitiveUtils.readLengthAndString(channel,buffer);
}
if (value == null) {
return null;
}
Long startNodeId=null;
Long endNodeId=null;
if (commandType == ADD_COMMAND && cls == RELATIONSHIP) {
startNodeId=PrimitiveUtils.readLong(channel,buffer);
endNodeId=PrimitiveUtils.readLong(channel,buffer);
if (startNodeId == null || endNodeId == null) {
return null;
}
}
IndexIdentifier identifier=new IndexIdentifier(cls,entityType,indexName,dataSource.indexStore.get(indexName));
switch (commandType) {
case ADD_COMMAND:
return cls == NODE ? new AddCommand(identifier,cls,entityId,key,value) : new AddRelationshipCommand(identifier,cls,new RelationshipId(entityId,startNodeId,endNodeId),key,value);
case REMOVE_COMMAND:
return new RemoveCommand(identifier,cls,entityId,key,value);
case CLEAR_COMMAND:
return new ClearCommand(identifier);
default :
throw new IOException("String_Node_Str" + commandType + "String_Node_Str");
}
}
}

Fixed version (ground truth):
static XaCommand readCommand(ReadableByteChannel channel,ByteBuffer buffer,LuceneDataSource dataSource) throws IOException {
  buffer.clear();
  buffer.limit(1);
  if (channel.read(buffer) != buffer.limit()) {
    return null;
  }
  buffer.flip();
  byte commandType=buffer.get();
  if (commandType == CREATE_INDEX_COMMAND) {
    buffer.clear();
    String name=PrimitiveUtils.readLengthAndString(channel,buffer);
    if (name == null) {
      return null;
    }
    int size=PrimitiveUtils.readInt(channel,buffer);
    Map<String,String> config=new HashMap<String,String>();
    for (int i=0; i < size; i++) {
      String key=PrimitiveUtils.readLengthAndString(channel,buffer);
      String value=PrimitiveUtils.readLengthAndString(channel,buffer);
      if (key == null || value == null) {
        return null;
      }
      config.put(key,value);
    }
    return new CreateIndexCommand(name,config);
  }
 else {
    buffer.clear();
    buffer.limit(18);
    if (channel.read(buffer) != buffer.limit()) {
      return null;
    }
    buffer.flip();
    byte cls=buffer.get();
    EntityType entityType=null;
    if (cls == NODE) {
      entityType=dataSource.nodeEntityType;
    }
 else     if (cls == RELATIONSHIP) {
      entityType=dataSource.relationshipEntityType;
    }
 else {
      return null;
    }
    int indexNameLength=buffer.getInt();
    long entityId=buffer.getLong();
    int keyCharLength=buffer.getInt();
    byte valueType=buffer.get();
    String indexName=PrimitiveUtils.readString(channel,buffer,indexNameLength);
    if (indexName == null) {
      return null;
    }
    String key=PrimitiveUtils.readString(channel,buffer,keyCharLength);
    if (key == null) {
      return null;
    }
    Object value=null;
    if (valueType >= VALUE_TYPE_INT && valueType <= VALUE_TYPE_DOUBLE) {
switch (valueType) {
case VALUE_TYPE_INT:
        value=PrimitiveUtils.readInt(channel,buffer);
      break;
case VALUE_TYPE_LONG:
    value=PrimitiveUtils.readLong(channel,buffer);
  break;
case VALUE_TYPE_FLOAT:
value=PrimitiveUtils.readFloat(channel,buffer);
break;
case VALUE_TYPE_DOUBLE:
value=PrimitiveUtils.readDouble(channel,buffer);
break;
}
}
 else if (valueType == VALUE_TYPE_STRING) {
value=PrimitiveUtils.readLengthAndString(channel,buffer);
}
if (value == null) {
return null;
}
Long startNodeId=null;
Long endNodeId=null;
if (commandType == ADD_COMMAND && cls == RELATIONSHIP) {
startNodeId=PrimitiveUtils.readLong(channel,buffer);
endNodeId=PrimitiveUtils.readLong(channel,buffer);
if (startNodeId == null || endNodeId == null) {
return null;
}
}
IndexIdentifier identifier=new IndexIdentifier(cls,entityType,indexName,dataSource.indexStore.get(indexName));
switch (commandType) {
case ADD_COMMAND:
return cls == NODE ? new AddCommand(identifier,cls,entityId,key,value) : new AddRelationshipCommand(identifier,cls,new RelationshipId(entityId,startNodeId,endNodeId),key,value);
case REMOVE_COMMAND:
return new RemoveCommand(identifier,cls,entityId,key,value);
case CLEAR_COMMAND:
return new ClearCommand(identifier);
default :
throw new IOException("String_Node_Str" + commandType + "String_Node_Str");
}
}
}