From 41eaf03bc85c61e0c10a9aef9ef922882245efdd Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 26 Jun 2017 23:22:28 +0200 Subject: [PATCH] Compatibility with covariant return type on JDK 9's ByteBuffer Issue: SPR-15686 --- .../core/io/buffer/DefaultDataBuffer.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index 4f45858fbb7..29a260f8305 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -29,11 +29,12 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * Default implementation of the {@link DataBuffer} interface that uses a {@link - * ByteBuffer} internally, with separate read and write positions. Constructed - * using the {@link DefaultDataBufferFactory}. + * Default implementation of the {@link DataBuffer} interface that uses a + * {@link ByteBuffer} internally, with separate read and write positions. + * Constructed using the {@link DefaultDataBufferFactory}. * * @author Arjen Poutsma + * @author Juergen Hoeller * @since 5.0 * @see DefaultDataBufferFactory */ @@ -304,15 +305,16 @@ public class DefaultDataBuffer implements DataBuffer { (oldBuffer.isDirect() ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity)); - // Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer final int remaining = readableByteCount(); + // Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer ((Buffer) oldBuffer).position(this.readPosition).limit(this.writePosition); newBuffer.put(oldBuffer); this.byteBuffer = newBuffer; this.readPosition = 0; this.writePosition = remaining; - oldBuffer.clear(); + // Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer + ((Buffer) oldBuffer).clear(); }