On Sat, 13 Mar 2021 22:29:23 GMT, Сергей Цыпанов 
<github.com+10835776+stsypa...@openjdk.org> wrote:

> In some cases wrapping of `InputStream` with `BufferedInputStream` is 
> redundant, e.g. in case the wrapped one is `ByteArrayOutputStream` which does 
> not require any buffer having one within.
> 
> Other cases are related to reading either a byte or short `byte[]`: in both 
> cases `BufferedInputStream.fill()` will be called resulting in load of much 
> bigger amount of data (8192 by default) than required.

src/java.base/share/classes/jdk/internal/jmod/JmodFile.java line 57:

> 55:             // validate the header
> 56:             byte[] magic = new byte[4];
> 57:             in.read(magic);

While you are there, this can be changed to magic = in.readNBytes(4) and throw 
IOException if magic.length != 4.

src/java.base/share/classes/jdk/internal/jmod/JmodFile.java line 58:

> 56:             byte[] magic = in.readNBytes(4);
> 57:             if (magic.length != 4) {
> 58:                 throw new IOException("Header expected to be of length 4, 
> but was " + magic.length);

Thanks for the update. If magic != 4 then it means the file is not a JMOD file 
or that it has been truncated.

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

PR: https://git.openjdk.java.net/jdk/pull/2992

Reply via email to