The contract for ObjectLoader.getBytes() says the caller can modify the returned array. UnpackedObjectLoader must copy the data and not return its internal cached byte array. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/lib/ObjectLoader.java | 7 ++++++- .../org/spearce/jgit/lib/PackedObjectLoader.java | 7 ------- .../org/spearce/jgit/lib/UnpackedObjectLoader.java | 4 ---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java index 5282491..87e861f 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java @@ -105,7 +105,12 @@ protected void setId(final ObjectId id) { * @throws IOException * the object cannot be read. */ - public abstract byte[] getBytes() throws IOException; + public final byte[] getBytes() throws IOException { + final byte[] data = getCachedBytes(); + final byte[] copy = new byte[data.length]; + System.arraycopy(data, 0, copy, 0, data.length); + return data; + } /** * Obtain a reference to the (possibly cached) bytes of this object. diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java index fa414d6..35983fe 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java @@ -80,13 +80,6 @@ public long getDataOffset() { return dataOffset; } - public final byte[] getBytes() throws IOException { - final byte[] data = getCachedBytes(); - final byte[] copy = new byte[data.length]; - System.arraycopy(data, 0, copy, 0, data.length); - return data; - } - /** * Copy raw object representation from storage to provided output stream. * <p> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java index 3c61254..3ad273f 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java @@ -200,10 +200,6 @@ public long getSize() { return objectSize; } - public byte[] getBytes() { - return bytes; - } - @Override public byte[] getCachedBytes() throws IOException { return bytes; -- 1.6.0.2.569.g798a2a -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html