JDK-8065262 : (bf spec) CharBuffer.chars() should make it clearer that the sequence starts from the buffer position
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-11-18
  • Updated: 2019-02-27
  • Resolved: 2019-02-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b09Fixed
Related Reports
CSR :  
Relates :  
Description
The spec for the following overriding method
https://docs.oracle.com/javase/8/docs/api/java/nio/CharBuffer.html#chars--
says (as the overridden method)
----------------------------
"Returns a stream of int zero-extending the char values from this sequence.
Returns: an IntStream of char values from this sequence "
----------------------------

The resulting stream is different for buffer instances produced differently:

Consider the following code:

        System.err.println(CharBuffer.allocate(1).put("A").chars().iterator().hasNext());
        System.err.println(CharBuffer.wrap("A").chars().iterator().next());

The output will be 

false
65

Having the current specification of CharBuffer.chars()
and not knowing the whole background of a typical CharBuffer behavior 
stream instance returned by the method might not be perfectly expected.
Comments
To clear this up, perhaps a sentence could merely be added to the specification of CharBuffer in X-Buffer.java.template: * <p> This class implements the {@link CharSequence} interface so that * character buffers may be used wherever character sequences are accepted, for * example in the regular-expression package {@link java.util.regex}. + * {@code CharSequence} methods operate relative to the current position of + * the buffer when they are invoked. * </p>
14-02-2019

Probably the specification needs to be updated to emphasize this? As so far it is just copied from the original method.
18-11-2014

This seems to be a bug in the test, the sequence of chars is the remaining chars in the buffer so the test needs to use flip to ensure that the position/limit is correct.
18-11-2014