Skip to content

Commit

Permalink
fix fabric8io#4201: jetty's bytebuffers may be immediately re-used
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Oct 18, 2022
1 parent 387237b commit 7c18d9f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,20 @@ public void onContent(Response response, LongConsumer demand, ByteBuffer content
this.demand.complete(demand);
}
try {
bodyConsumer.consume(process(response, content), this);
// we must clone as the buffer can be reused after the call to succeeded
bodyConsumer.consume(process(response, clone(content)), this);
callback.succeeded();
} catch (Exception e) {
callback.failed(e);
}
}

protected abstract T process(Response response, ByteBuffer content);

public static ByteBuffer clone(ByteBuffer original) {
ByteBuffer clone = ByteBuffer.allocate(original.remaining());
clone.put(original);
clone.flip();
return clone;
}
}

0 comments on commit 7c18d9f

Please sign in to comment.