RFR: 8155259: Suspicious buffer allocation in com.sun.tools.javac.file.BaseFileManager [v3]

Archie L. Cobbs duke at openjdk.org
Mon Dec 19 15:44:53 UTC 2022


> JDK-8155259 notes that in `BaseFileManager` this code:
> 
> ByteBuffer.allocate(capacity + capacity>>1)
> 
> is actually equivalent (assuming no overflow) to:
> 
> ByteBuffer.allocate(capacity)
> 
> because in Java the `+` operator has higher precedence than the `>>` operator.
> 
> In the bug it is suggested that this be changed to reflect the presumed original intent to over-allocate by 50%, i.e.:
> 
> ByteBuffer.allocate(capacity + (capacity>>1))
> 
> however, this patch is more conservative in that it leaves the existing behavior alone and instead just simplifies it to:
> 
> ByteBuffer.allocate(capacity)
> 
> allowing us to at least resolve JDK-8155259.

Archie L. Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'master' into JDK-8155259
 - Merge branch 'master' into JDK-8155259
 - 8155259: Suspicious buffer allocation in com.sun.tools.javac.file.BaseFileManager

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/10803/files
  - new: https://git.openjdk.org/jdk/pull/10803/files/4dfeba3b..f79f51fe

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=10803&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=10803&range=01-02

  Stats: 136482 lines in 2312 files changed: 69468 ins; 45399 del; 21615 mod
  Patch: https://git.openjdk.org/jdk/pull/10803.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10803/head:pull/10803

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


More information about the compiler-dev mailing list