diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java index bac22b0..b8643e3 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java @@ -57,10 +57,15 @@ public abstract class AbstractBlob implements Blob { String ai = a.getContentIdentity(); String bi = b.getContentIdentity(); - //Check for identity first. If they are same then its - //definitely same blob. If not we need to check further. - if (ai != null && bi != null && ai.equals(bi)){ - return true; + //Check for identity first. If both identities exist, + //the blobs are equal if the identities are equal, and + //the blobs are not equal if the identities are not + //equal. + //This is because the identities are currently a + //hash of the blob content. If this were to ever change + //this would also need to revert to the old mechanism. + if (ai != null && bi != null) { + return ai.equals(bi); } try { diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlobTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlobTest.java index 6f0dbf8..3aea0ac 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlobTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlobTest.java @@ -39,11 +39,20 @@ public class AbstractBlobTest { byte[] data = bytes(100); Blob a = new TestBlob(data, "id1", false); Blob b = new TestBlob(data, "id1", false); + // Blobs are considered equal if their identities are equal. assertTrue(AbstractBlob.equal(a, b)); - Blob a2 = new TestBlob(data, "id1", true); - Blob b2 = new TestBlob(data, "id2", true); - assertTrue("Blobs with different id but same content should match", AbstractBlob.equal(a2, b2)); + Blob a2 = new TestBlob(data, "id1", false); + Blob b2 = new TestBlob(data, "id2", false); + // Blobs are not considered equal if their identities are not equal. (See OAK-5253) + assertFalse(AbstractBlob.equal(a2, b2)); + + Blob a3 = new TestBlob(data, "id1", true); + Blob b3 = new TestBlob(data, "id2", true); + // As of OAK-5253, Blobs are not considered equal if their identities are not equal, + // even if the content is equal. This is an optimization based on the implementation + // where blob identities are a hash of the content. + assertFalse("Blobs with different id but same content should not match", AbstractBlob.equal(a3, b3)); } @Test