Skip to content

Commit

Permalink
fix: npe because of clone is not thread safe in BreakpointInfo
Browse files Browse the repository at this point in the history
Closes #143
  • Loading branch information
Tianhua Ran committed Oct 29, 2019
1 parent aaf81a5 commit 2a0d20c
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ public void setEtag(String etag) {

public long getTotalOffset() {
long offset = 0;
ArrayList<BlockInfo> list = (ArrayList<BlockInfo>) ((ArrayList) blockInfoList).clone();

final int count = list.size();
for (int i = 0; i < count; i++) {
final BlockInfo info = list.get(i);
offset += info.getCurrentOffset();
final Object[] blocks = blockInfoList.toArray();
if (blocks != null) {
for (Object block : blocks) {
if (block instanceof BlockInfo) {
offset += ((BlockInfo) block).getCurrentOffset();
}
}
}
return offset;
}
Expand All @@ -138,9 +139,13 @@ public long getTotalLength() {
if (isChunked()) return getTotalOffset();

long length = 0;
ArrayList<BlockInfo> list = (ArrayList<BlockInfo>) ((ArrayList) blockInfoList).clone();
for (BlockInfo info : list) {
length += info.getContentLength();
final Object[] blocks = blockInfoList.toArray();
if (blocks != null) {
for (Object block : blocks) {
if (block instanceof BlockInfo) {
length += ((BlockInfo) block).getContentLength();
}
}
}

return length;
Expand Down

0 comments on commit 2a0d20c

Please sign in to comment.