JDK-7130631 : (bf) Immutable java.nio.Buffer
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-01-17
  • Updated: 2012-03-20
  • Resolved: 2012-01-27
Description
A DESCRIPTION OF THE REQUEST :
Please provide a way to construct an immutable object from java.nio.Buffer and its subclasses.

Currently, classes that take ByteBuffer as input must make defensive copies to prevent the buffer from being modified in the future.

ByteBuffer.isReadOnly() doesn't guarantee that the original owner won't modifying the buffer.

This can't be implemented by end-users because ByteBuffer cannot be subclassed.

JUSTIFICATION :
Performance, readability and security improvements.


CUSTOMER SUBMITTED WORKAROUND :
Create defensive copies of the buffer

Comments
EVALUATION We didn't hear any more from the submitter but hopefully it is clear that a completely immutable buffer isn't really feasible because reading from a buffer requires adjusting the buffer's position.
27-01-2012

EVALUATION This RFE doesn't really make sense as buffers are inheritly mutable - to read from a container involves adjusting the position for example. I think the submitter needs to include a better description of what they are doing.
18-01-2012