diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBuffer.java b/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBuffer.java index 5c24dc2ac80..a41a99aa69a 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBuffer.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBuffer.java @@ -37,8 +37,6 @@ class LeakAwareDataBuffer implements PooledDataBuffer { private final LeakAwareDataBufferFactory dataBufferFactory; - private int refCount = 1; - LeakAwareDataBuffer(DataBuffer delegate, LeakAwareDataBufferFactory dataBufferFactory) { Assert.notNull(delegate, "Delegate must not be null"); @@ -67,19 +65,24 @@ class LeakAwareDataBuffer implements PooledDataBuffer { @Override public boolean isAllocated() { - return this.refCount > 0; + return this.delegate instanceof PooledDataBuffer && + ((PooledDataBuffer) this.delegate).isAllocated(); } @Override public PooledDataBuffer retain() { - this.refCount++; + if (this.delegate instanceof PooledDataBuffer) { + ((PooledDataBuffer) this.delegate).retain(); + } return this; } @Override public boolean release() { - this.refCount--; - return this.refCount == 0; + if (this.delegate instanceof PooledDataBuffer) { + ((PooledDataBuffer) this.delegate).release(); + } + return isAllocated(); } // delegation diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBufferFactory.java b/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBufferFactory.java index e79da102758..62900ad9f53 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBufferFactory.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBufferFactory.java @@ -99,16 +99,16 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory { @Override public DataBuffer allocateBuffer() { - return allocateBufferInternal(this.delegate.allocateBuffer()); + return createLeakAwareDataBuffer(this.delegate.allocateBuffer()); } @Override public DataBuffer allocateBuffer(int initialCapacity) { - return allocateBufferInternal(this.delegate.allocateBuffer(initialCapacity)); + return createLeakAwareDataBuffer(this.delegate.allocateBuffer(initialCapacity)); } @NotNull - private DataBuffer allocateBufferInternal(DataBuffer delegateBuffer) { + private DataBuffer createLeakAwareDataBuffer(DataBuffer delegateBuffer) { LeakAwareDataBuffer dataBuffer = new LeakAwareDataBuffer(delegateBuffer, this); this.created.add(dataBuffer); return dataBuffer;