RFR: 8343039: Remove jdk.internal.misc.InternalLock and usages from java.io

Chen Liang liach at openjdk.org
Wed Nov 13 03:20:53 UTC 2024


On Wed, 13 Nov 2024 02:41:05 GMT, ExE Boss <duke at openjdk.org> wrote:

>> Uses of `InternalLock` are removed and `synchronized` is reinstated.
>
> src/java.base/share/classes/java/io/BufferedInputStream.java line 241:
> 
>> 239:         }
>> 240:         initialSize = size;
>> 241:         buf = new byte[size];
> 
> This should probably still retain the lazy buffer array creation:
> Suggestion:
> 
> size;
>         if (getClass() == BufferedInputStream.class) {
>             // lazily create buffer when not subclassed
>             buf = EMPTY;
>         } else {
>             // eagerly create buffer when subclassed
>             buf = new byte[size];
>         }

Indeed.  This and that for BufferedOutputStream are for backward compatibility with subclasses.  We cannot control when subclasses access the `buf` field after the constructor call, so laziness was impossible.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22048#discussion_r1839323249


More information about the core-libs-dev mailing list