--- old/src/java.base/share/classes/java/nio/Buffer.java 2014-09-16 22:40:25.473782586 +0100 +++ new/src/java.base/share/classes/java/nio/Buffer.java 2014-09-16 22:40:25.137782593 +0100 @@ -239,7 +239,7 @@ * @throws IllegalArgumentException * If the preconditions on newPosition do not hold */ - public final Buffer position(int newPosition) { + public Buffer position(int newPosition) { if ((newPosition > limit) || (newPosition < 0)) throw new IllegalArgumentException(); position = newPosition; @@ -270,7 +270,7 @@ * @throws IllegalArgumentException * If the preconditions on newLimit do not hold */ - public final Buffer limit(int newLimit) { + public Buffer limit(int newLimit) { if ((newLimit > capacity) || (newLimit < 0)) throw new IllegalArgumentException(); limit = newLimit; @@ -284,7 +284,7 @@ * * @return This buffer */ - public final Buffer mark() { + public Buffer mark() { mark = position; return this; } @@ -300,7 +300,7 @@ * @throws InvalidMarkException * If the mark has not been set */ - public final Buffer reset() { + public Buffer reset() { int m = mark; if (m < 0) throw new InvalidMarkException(); @@ -325,7 +325,7 @@ * * @return This buffer */ - public final Buffer clear() { + public Buffer clear() { position = 0; limit = capacity; mark = -1; @@ -353,7 +353,7 @@ * * @return This buffer */ - public final Buffer flip() { + public Buffer flip() { limit = position; position = 0; mark = -1; @@ -375,7 +375,7 @@ * * @return This buffer */ - public final Buffer rewind() { + public Buffer rewind() { position = 0; mark = -1; return this; --- old/src/java.base/share/classes/java/nio/MappedByteBuffer.java 2014-09-16 22:40:25.841782579 +0100 +++ new/src/java.base/share/classes/java/nio/MappedByteBuffer.java 2014-09-16 22:40:25.729782581 +0100 @@ -208,4 +208,69 @@ private native boolean isLoaded0(long address, long length, int pageCount); private native void load0(long address, long length); private native void force0(FileDescriptor fd, long address, long length); + + // -- Covariant return type overrides + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer position(int newPosition) { + super.position(newPosition); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer limit(int newLimit) { + super.limit(newLimit); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer mark() { + super.mark(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer reset() { + super.reset(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer clear() { + super.clear(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer flip() { + super.flip(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public final MappedByteBuffer rewind() { + super.rewind(); + return this; + } } --- old/src/java.base/share/classes/java/nio/X-Buffer.java.template 2014-09-16 22:40:26.197782571 +0100 +++ new/src/java.base/share/classes/java/nio/X-Buffer.java.template 2014-09-16 22:40:26.085782574 +0100 @@ -1025,6 +1025,99 @@ return offset; } + // -- Covariant return type overrides + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer position(int newPosition) { + super.position(newPosition); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer limit(int newLimit) { + super.limit(newLimit); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer mark() { + super.mark(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer reset() { + super.reset(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer clear() { + super.clear(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer flip() { + super.flip(); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public +#if[!byte] + final +#end[!byte] + $Type$Buffer rewind() { + super.rewind(); + return this; + } + /** * Compacts this buffer  (optional operation). * --- old/src/java.base/share/classes/sun/security/ssl/CipherBox.java 2014-09-16 22:40:26.585782564 +0100 +++ new/src/java.base/share/classes/sun/security/ssl/CipherBox.java 2014-09-16 22:40:26.469782566 +0100 @@ -560,7 +560,7 @@ + newLen); hd.encodeBuffer( - (ByteBuffer)bb.duplicate().position(pos), System.out); + bb.duplicate().position(pos), System.out); } catch (IOException e) { } } @@ -790,7 +790,7 @@ // The padding data should be filled with the padding length value. int[] results = checkPadding( - (ByteBuffer)bb.duplicate().position(offset + newLen), + bb.duplicate().position(offset + newLen), (byte)(padLen & 0xFF)); if (protocolVersion.v >= ProtocolVersion.TLS10.v) { if (results[0] != 0) { // padding data has invalid bytes --- old/src/java.base/share/classes/sun/security/ssl/EngineInputRecord.java 2014-09-16 22:40:26.941782557 +0100 +++ new/src/java.base/share/classes/sun/security/ssl/EngineInputRecord.java 2014-09-16 22:40:26.825782559 +0100 @@ -349,8 +349,7 @@ /* * Copy data out of buffer, it's ready to go. */ - ByteBuffer netBB = (ByteBuffer) - (ByteBuffer.allocate(len).put(buf, 0, len).flip()); + ByteBuffer netBB = ByteBuffer.allocate(len).put(buf, 0, len).flip(); engine.writer.putOutboundDataSync(netBB); } --- old/src/java.base/share/classes/sun/security/ssl/EngineOutputRecord.java 2014-09-16 22:40:27.289782550 +0100 +++ new/src/java.base/share/classes/sun/security/ssl/EngineOutputRecord.java 2014-09-16 22:40:27.173782552 +0100 @@ -113,9 +113,7 @@ /* * Copy data out of buffer, it's ready to go. */ - ByteBuffer netBB = (ByteBuffer) - ByteBuffer.allocate(len).put(buf, off, len).flip(); - + ByteBuffer netBB = ByteBuffer.allocate(len).put(buf, off, len).flip(); writer.putOutboundData(netBB); } --- old/test/java/io/FileDescriptor/Finalize.java 2014-09-16 22:40:27.693782541 +0100 +++ new/test/java/io/FileDescriptor/Finalize.java 2014-09-16 22:40:27.525782545 +0100 @@ -245,9 +245,10 @@ * write to fc2 - when fos1 is gc'ed and finalizer is run, * write to fc2 should not fail */ - bb = ByteBuffer.allocateDirect(data.length); - bb = bb.put(data); - bb = (ByteBuffer) bb.flip(); + bb = ByteBuffer.allocateDirect(data.length) + .put(data) + .flip(); + ret = fc2.write(bb); System.out.println("Wrote:" + ret + " bytes to fc2"); fc2.close(); --- old/test/java/nio/charset/CharsetEncoder/Flush.java 2014-09-16 22:40:28.065782534 +0100 +++ new/test/java/nio/charset/CharsetEncoder/Flush.java 2014-09-16 22:40:27.921782537 +0100 @@ -35,7 +35,7 @@ public class Flush { private static byte[] contents(ByteBuffer bb) { byte[] contents = new byte[bb.position()]; - ((ByteBuffer)(bb.duplicate().flip())).get(contents); + bb.duplicate().flip().get(contents); return contents; } --- old/test/sun/nio/cs/TestUTF_16.java 2014-09-16 22:40:28.453782526 +0100 +++ new/test/sun/nio/cs/TestUTF_16.java 2014-09-16 22:40:28.281782530 +0100 @@ -150,7 +150,7 @@ if (CoderResult.OVERFLOW != Charset.forName("UTF_16") .newDecoder() - .decode((ByteBuffer)(ByteBuffer.allocate(4) + .decode((ByteBuffer.allocate(4) .put(new byte[] {(byte)0xd8,(byte)0x00, (byte)0xdc,(byte)0x01}) --- old/test/sun/nio/cs/TestUTF_32.java 2014-09-16 22:40:28.805782519 +0100 +++ new/test/sun/nio/cs/TestUTF_32.java 2014-09-16 22:40:28.685782522 +0100 @@ -184,7 +184,7 @@ if (CoderResult.OVERFLOW != Charset.forName("UTF_32") .newDecoder() - .decode((ByteBuffer)(ByteBuffer.allocate(4) + .decode((ByteBuffer.allocate(4) .put(new byte[] {(byte)0,(byte)1, (byte)0,(byte)01}) .flip()),