Permalink
Browse files

Fix erroneuous assertion in BasicObjectId.

The assertion failed if more than one document (with an ObjectId) were in the
buffer.
  • Loading branch information...
1 parent 2638eb1 commit 2e282c7b747ec8c89c357bf11252dd795a330137 @kohanyirobert kohanyirobert committed Feb 7, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/main/java/com/github/kohanyirobert/ebson/BasicObjectId.java
View
6 src/main/java/com/github/kohanyirobert/ebson/BasicObjectId.java
@@ -24,12 +24,14 @@
private final ByteBuffer objectId = ByteBuffer.allocate(OBJECT_ID_LENGTH).order(ByteOrder.BIG_ENDIAN);
BasicObjectId(ByteBuffer buffer) {
- int oldLimit = buffer.limit();
+ int oldPosition = buffer.position();
+ int oldLimit = buffer.limit();
buffer.limit(buffer.position() + OBJECT_ID_LENGTH);
objectId.put(buffer).flip();
+ buffer.limit(oldLimit);
- assert buffer.limit() == oldLimit;
+ assert buffer.position() == oldPosition + OBJECT_ID_LENGTH;
time = ByteBuffer.wrap(objectId.array(), 0, TIME_LENGTH).order(ByteOrder.BIG_ENDIAN);
machineId = ByteBuffer.wrap(objectId.array(), TIME_LENGTH, MACHINE_ID_LENGTH).order(ByteOrder.LITTLE_ENDIAN);

0 comments on commit 2e282c7

Please sign in to comment.