RFR: 8277501: Revisit PathFileObject.getCharContent and friends

Archie L. Cobbs duke at openjdk.org
Sun Feb 26 00:23:51 UTC 2023


The method `BaseFileManager.makeByteBuffer()` assumes that the result from`InputStream.available()` is always accurate, but this is not guaranteed.

This patch cleans up this logic by piggybacking on a similar cleanup that was recently done for [JDK-8302514](https://bugs.openjdk.org/browse/JDK-8302514).

This change also makes a couple of other changes:

(1) Adjust the sematics of `ByteBuffer.appendStream()` so that it doesn't also close the input, which is abnormal for a method like this.

(2) Add synchronization to the buffer caching in `BaseFileManager.makeByteBuffer()` because, according to the API documentation for `JavaFileManager`:
> An object of this interface is not required to support multi-threaded access, that is, be synchronized. However, it must support concurrent access to different file objects created by this object. 

`BaseFileManager.makeByteBuffer()` is invoked from `PathFileObject` and so the per-file object thread-safety requirement would apply here.

-------------

Commit messages:
 - Avoid over-reliance on InputStream.available() in BaseFileManager.makeByteBuffer().
 - Adjust the semantics of ByteBuffer.appendStream() to not close the stream.

Changes: https://git.openjdk.org/jdk/pull/12755/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12755&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8277501
  Stats: 93 lines in 3 files changed: 27 ins; 34 del; 32 mod
  Patch: https://git.openjdk.org/jdk/pull/12755.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/12755/head:pull/12755

PR: https://git.openjdk.org/jdk/pull/12755


More information about the compiler-dev mailing list