Program: 132326
Project: 132326
Buggy source:
/** 
 * Feed the persistenceManager with the knowledge to handle database-modifying related requests.
 */
private void initializePersistenceManager(){
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_CREATE,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int numIndices=(Integer)args[1];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[databaseName.getBytes().length + (Integer.SIZE * 3 / 8)]);
      buf.putInt(-1);
      buf.putString(databaseName);
      buf.putInt(numIndices);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      String dbName=serialized.getString();
      int indices=serialized.getInt();
      serialized.flip();
      return new Object[]{dbName,indices,null};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int numIndices=(Integer)args[1];
      ByteRangeComparator[] com=(ByteRangeComparator[])args[2];
      if (com == null) {
        ByteRangeComparator[] comps=new ByteRangeComparator[numIndices];
        final ByteRangeComparator defaultComparator=compInstances.get(DefaultByteRangeComparator.class.getName());
        for (int i=0; i < numIndices; i++) {
          comps[i]=defaultComparator;
        }
        com=comps;
      }
      DatabaseImpl db=null;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (dbsByName.containsKey(databaseName)) {
            throw new BabuDBException(ErrorCode.DB_EXISTS,"String_Node_Str" + databaseName + "String_Node_Str");
          }
          final int dbId=nextDbId++;
          db=new DatabaseImpl(dbs,new LSMDatabase(databaseName,dbId,dbs.getConfig().getBaseDir() + databaseName + File.separatorChar,numIndices,false,com,dbs.getConfig().getCompression(),dbs.getConfig().getMaxNumRecordsPerBlock(),dbs.getConfig().getMaxBlockFileSize(),dbs.getConfig().getDisableMMap(),dbs.getConfig().getMMapLimit()));
          dbsById.put(dbId,db);
          dbsByName.put(databaseName,db);
          dbs.getDBConfigFile().save();
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_DELETE,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[(Integer.SIZE / 2) + databaseName.getBytes().length]);
      buf.putInt(-1);
      buf.putString(databaseName);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      String dbName=serialized.getString();
      serialized.flip();
      return new Object[]{dbName};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int dbId=-1;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (!dbsByName.containsKey(databaseName)) {
            throw new BabuDBException(ErrorCode.NO_SUCH_DB,"String_Node_Str" + databaseName + "String_Node_Str");
          }
          final LSMDatabase db=((DatabaseImpl)dbsByName.get(databaseName)).getLSMDB();
          dbId=db.getDatabaseId();
          dbsByName.remove(databaseName);
          dbsById.remove(dbId);
          ((SnapshotManagerImpl)dbs.getSnapshotManager()).deleteAllSnapshots(databaseName);
          dbs.getDBConfigFile().save();
          File dbDir=new File(dbs.getConfig().getBaseDir(),databaseName);
          if (dbDir.exists())           FSUtils.delTree(dbDir);
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_COPY,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String sourceDB=(String)args[0];
      String destDB=(String)args[1];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[(Integer.SIZE / 2) + sourceDB.getBytes().length + destDB.getBytes().length]);
      buf.putInt(-1);
      buf.putInt(-1);
      buf.putString(sourceDB);
      buf.putString(destDB);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      serialized.getInt();
      String sourceDB=serialized.getString();
      String destDB=serialized.getString();
      serialized.flip();
      return new Object[]{sourceDB,destDB};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String sourceDB=(String)args[0];
      String destDB=(String)args[1];
      DatabaseImpl sDB=(DatabaseImpl)dbsByName.get(sourceDB);
      if (sDB == null) {
        throw new BabuDBException(ErrorCode.NO_SUCH_DB,"String_Node_Str" + sourceDB + "String_Node_Str");
      }
      int dbId;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (dbsByName.containsKey(destDB)) {
            throw new BabuDBException(ErrorCode.DB_EXISTS,"String_Node_Str" + destDB + "String_Node_Str");
          }
          dbId=nextDbId++;
          dbsByName.put(destDB,null);
          dbs.getDBConfigFile().save();
        }
      }
      try {
        sDB.proceedSnapshot(destDB);
      }
 catch (      InterruptedException i) {
        throw new BabuDBException(ErrorCode.INTERNAL_ERROR,"String_Node_Str",i);
      }
      Database newDB=new DatabaseImpl(dbs,new LSMDatabase(destDB,dbId,dbs.getConfig().getBaseDir() + destDB + File.separatorChar,sDB.getLSMDB().getIndexCount(),true,sDB.getComparators(),dbs.getConfig().getCompression(),dbs.getConfig().getMaxNumRecordsPerBlock(),dbs.getConfig().getMaxBlockFileSize(),dbs.getConfig().getDisableMMap(),dbs.getConfig().getMMapLimit()));
synchronized (dbModificationLock) {
        dbsById.put(dbId,newDB);
        dbsByName.put(destDB,newDB);
        dbs.getDBConfigFile().save();
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_SNAP,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      int dbId=(Integer)args[0];
      SnapshotConfig snap=(SnapshotConfig)args[1];
      ReusableBuffer buf=null;
      try {
        ByteArrayOutputStream bout=new ByteArrayOutputStream();
        ObjectOutputStream oout=new ObjectOutputStream(bout);
        oout.writeInt(dbId);
        oout.writeObject(snap);
        buf=ReusableBuffer.wrap(bout.toByteArray());
        oout.close();
      }
 catch (      IOException exc) {
        throw new BabuDBException(ErrorCode.IO_ERROR,"String_Node_Str" + snap.getClass(),exc);
      }
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      ObjectInputStream oin=null;
      try {
        oin=new ObjectInputStream(new ByteArrayInputStream(serialized.array()));
        int dbId=oin.readInt();
        SnapshotConfig snap=(SnapshotConfig)oin.readObject();
        return new Object[]{dbId,snap};
      }
 catch (      Exception e) {
        throw new BabuDBException(ErrorCode.IO_ERROR,"String_Node_Str" + PAYLOAD_TYPE_SNAP + "String_Node_Str"+ e.getMessage(),e);
      }
 finally {
        try {
          serialized.flip();
          if (oin != null)           oin.close();
        }
 catch (        IOException ioe) {
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_INSERT,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      BabuDBInsertGroup irg=(BabuDBInsertGroup)args[0];
      int size=irg.getRecord().getSize();
      ReusableBuffer buf=BufferPool.allocate(size);
      irg.getRecord().serialize(buf);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      InsertRecordGroup irg=InsertRecordGroup.deserialize(serialized);
      serialized.flip();
      return new Object[]{irg,null,null};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      BabuDBInsertGroup irg=(BabuDBInsertGroup)args[0];
      LSMDatabase lsmDB=(LSMDatabase)args[1];
      if (lsmDB == null) {
        lsmDB=((DatabaseImpl)dbsById.get(irg.getRecord().getDatabaseId())).getLSMDB();
      }
      int numIndices=lsmDB.getIndexCount();
      for (      InsertRecord ir : irg.getRecord().getInserts()) {
        if ((ir.getIndexId() >= numIndices) || (ir.getIndexId() < 0)) {
          throw new BabuDBException(ErrorCode.NO_SUCH_INDEX,"String_Node_Str" + ir.getIndexId() + "String_Node_Str");
        }
      }
    }
    @SuppressWarnings("String_Node_Str") @Override public void after(    Object[] args){
      BabuDBInsertGroup irg=(BabuDBInsertGroup)args[0];
      LSMDatabase lsmDB=(LSMDatabase)args[1];
      if (lsmDB == null) {
        lsmDB=((DatabaseImpl)dbsById.get(irg.getRecord().getDatabaseId())).getLSMDB();
      }
      BabuDBRequestResultImpl<Object> listener=(BabuDBRequestResultImpl<Object>)args[2];
      if (dbs.getConfig().getSyncMode() != SyncMode.ASYNC) {
        for (        InsertRecord ir : irg.getRecord().getInserts()) {
          LSMTree index=lsmDB.getIndex(ir.getIndexId());
          if (ir.getValue() != null) {
            index.insert(ir.getKey(),ir.getValue());
          }
 else {
            index.delete(ir.getKey());
          }
        }
        if (listener != null)         listener.finished();
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Feed the persistenceManager with the knowledge to handle database-modifying related requests.
 */
private void initializePersistenceManager(){
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_CREATE,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int numIndices=(Integer)args[1];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[databaseName.getBytes().length + (Integer.SIZE * 3 / 8)]);
      buf.putInt(-1);
      buf.putString(databaseName);
      buf.putInt(numIndices);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      String dbName=serialized.getString();
      int indices=serialized.getInt();
      serialized.flip();
      return new Object[]{dbName,indices,null};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int numIndices=(Integer)args[1];
      ByteRangeComparator[] com=(ByteRangeComparator[])args[2];
      if (com == null) {
        ByteRangeComparator[] comps=new ByteRangeComparator[numIndices];
        final ByteRangeComparator defaultComparator=compInstances.get(DefaultByteRangeComparator.class.getName());
        for (int i=0; i < numIndices; i++) {
          comps[i]=defaultComparator;
        }
        com=comps;
      }
      DatabaseImpl db=null;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (dbsByName.containsKey(databaseName)) {
            throw new BabuDBException(ErrorCode.DB_EXISTS,"String_Node_Str" + databaseName + "String_Node_Str");
          }
          final int dbId=nextDbId++;
          db=new DatabaseImpl(dbs,new LSMDatabase(databaseName,dbId,dbs.getConfig().getBaseDir() + databaseName + File.separatorChar,numIndices,false,com,dbs.getConfig().getCompression(),dbs.getConfig().getMaxNumRecordsPerBlock(),dbs.getConfig().getMaxBlockFileSize(),dbs.getConfig().getDisableMMap(),dbs.getConfig().getMMapLimit()));
          dbsById.put(dbId,db);
          dbsByName.put(databaseName,db);
          dbs.getDBConfigFile().save();
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_DELETE,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[(Integer.SIZE / 2) + databaseName.getBytes().length]);
      buf.putInt(-1);
      buf.putString(databaseName);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      String dbName=serialized.getString();
      serialized.flip();
      return new Object[]{dbName};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String databaseName=(String)args[0];
      int dbId=-1;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (!dbsByName.containsKey(databaseName)) {
            throw new BabuDBException(ErrorCode.NO_SUCH_DB,"String_Node_Str" + databaseName + "String_Node_Str");
          }
          final LSMDatabase db=((DatabaseImpl)dbsByName.get(databaseName)).getLSMDB();
          dbId=db.getDatabaseId();
          dbsByName.remove(databaseName);
          dbsById.remove(dbId);
          ((SnapshotManagerImpl)dbs.getSnapshotManager()).deleteAllSnapshots(databaseName);
          dbs.getDBConfigFile().save();
          File dbDir=new File(dbs.getConfig().getBaseDir(),databaseName);
          if (dbDir.exists())           FSUtils.delTree(dbDir);
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_COPY,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      String sourceDB=(String)args[0];
      String destDB=(String)args[1];
      ReusableBuffer buf=ReusableBuffer.wrap(new byte[(Integer.SIZE / 2) + sourceDB.getBytes().length + destDB.getBytes().length]);
      buf.putInt(-1);
      buf.putInt(-1);
      buf.putString(sourceDB);
      buf.putString(destDB);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      serialized.getInt();
      serialized.getInt();
      String sourceDB=serialized.getString();
      String destDB=serialized.getString();
      serialized.flip();
      return new Object[]{sourceDB,destDB};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      String sourceDB=(String)args[0];
      String destDB=(String)args[1];
      DatabaseImpl sDB=(DatabaseImpl)dbsByName.get(sourceDB);
      if (sDB == null) {
        throw new BabuDBException(ErrorCode.NO_SUCH_DB,"String_Node_Str" + sourceDB + "String_Node_Str");
      }
      int dbId;
synchronized (getDBModificationLock()) {
synchronized (dbs.getCheckpointer()) {
          if (dbsByName.containsKey(destDB)) {
            throw new BabuDBException(ErrorCode.DB_EXISTS,"String_Node_Str" + destDB + "String_Node_Str");
          }
          dbId=nextDbId++;
          dbsByName.put(destDB,null);
          dbs.getDBConfigFile().save();
        }
      }
      try {
        sDB.proceedSnapshot(destDB);
      }
 catch (      InterruptedException i) {
        throw new BabuDBException(ErrorCode.INTERNAL_ERROR,"String_Node_Str",i);
      }
      Database newDB=new DatabaseImpl(dbs,new LSMDatabase(destDB,dbId,dbs.getConfig().getBaseDir() + destDB + File.separatorChar,sDB.getLSMDB().getIndexCount(),true,sDB.getComparators(),dbs.getConfig().getCompression(),dbs.getConfig().getMaxNumRecordsPerBlock(),dbs.getConfig().getMaxBlockFileSize(),dbs.getConfig().getDisableMMap(),dbs.getConfig().getMMapLimit()));
synchronized (dbModificationLock) {
        dbsById.put(dbId,newDB);
        dbsByName.put(destDB,newDB);
        dbs.getDBConfigFile().save();
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_SNAP,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      int dbId=(Integer)args[0];
      SnapshotConfig snap=(SnapshotConfig)args[1];
      ReusableBuffer buf=null;
      try {
        ByteArrayOutputStream bout=new ByteArrayOutputStream();
        ObjectOutputStream oout=new ObjectOutputStream(bout);
        oout.writeInt(dbId);
        oout.writeObject(snap);
        buf=ReusableBuffer.wrap(bout.toByteArray());
        oout.close();
      }
 catch (      IOException exc) {
        throw new BabuDBException(ErrorCode.IO_ERROR,"String_Node_Str" + snap.getClass(),exc);
      }
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      ObjectInputStream oin=null;
      try {
        oin=new ObjectInputStream(new ByteArrayInputStream(serialized.array()));
        int dbId=oin.readInt();
        SnapshotConfig snap=(SnapshotConfig)oin.readObject();
        return new Object[]{dbId,snap};
      }
 catch (      Exception e) {
        throw new BabuDBException(ErrorCode.IO_ERROR,"String_Node_Str" + PAYLOAD_TYPE_SNAP + "String_Node_Str"+ e.getMessage(),e);
      }
 finally {
        try {
          serialized.flip();
          if (oin != null)           oin.close();
        }
 catch (        IOException ioe) {
        }
      }
    }
  }
);
  dbs.getPersistenceManager().registerInMemoryProcessing(PAYLOAD_TYPE_INSERT,new InMemoryProcessing(){
    @Override public ReusableBuffer serializeRequest(    Object[] args) throws BabuDBException {
      InsertRecordGroup irg=(InsertRecordGroup)args[0];
      int size=irg.getSize();
      ReusableBuffer buf=BufferPool.allocate(size);
      irg.serialize(buf);
      buf.flip();
      return buf;
    }
    @Override public Object[] deserializeRequest(    ReusableBuffer serialized) throws BabuDBException {
      InsertRecordGroup irg=InsertRecordGroup.deserialize(serialized);
      serialized.flip();
      return new Object[]{irg,null,null};
    }
    @Override public void before(    Object[] args) throws BabuDBException {
      InsertRecordGroup irg=(InsertRecordGroup)args[0];
      LSMDatabase lsmDB=(LSMDatabase)args[1];
      if (lsmDB == null) {
        lsmDB=((DatabaseImpl)dbsById.get(irg.getDatabaseId())).getLSMDB();
      }
      int numIndices=lsmDB.getIndexCount();
      for (      InsertRecord ir : irg.getInserts()) {
        if ((ir.getIndexId() >= numIndices) || (ir.getIndexId() < 0)) {
          throw new BabuDBException(ErrorCode.NO_SUCH_INDEX,"String_Node_Str" + ir.getIndexId() + "String_Node_Str");
        }
      }
    }
    @SuppressWarnings("String_Node_Str") @Override public void after(    Object[] args){
      InsertRecordGroup irg=(InsertRecordGroup)args[0];
      LSMDatabase lsmDB=(LSMDatabase)args[1];
      if (lsmDB == null) {
        lsmDB=((DatabaseImpl)dbsById.get(irg.getDatabaseId())).getLSMDB();
      }
      BabuDBRequestResultImpl<Object> listener=(BabuDBRequestResultImpl<Object>)args[2];
      if (dbs.getConfig().getSyncMode() != SyncMode.ASYNC) {
        for (        InsertRecord ir : irg.getInserts()) {
          LSMTree index=lsmDB.getIndex(ir.getIndexId());
          if (ir.getValue() != null) {
            index.insert(ir.getKey(),ir.getValue());
          }
 else {
            index.delete(ir.getKey());
          }
        }
        if (listener != null)         listener.finished();
      }
    }
  }
);
}