[Java ] "read(byte[],int,int)" should be overridden


(Alejandro Zuzek) #1

java.io.InputStream subclasses are forced to reimplement int read() but are not forced to reimplement read(byte[],int,int). If read(byte[],int,int) is not overwritten, the default implementation in java.io.InputStream repeatedly calls read() but most InputStream implementations could do much better by reading multiple bytes at a time.

There is an existing rule which is similar to this but for the write() method in OutputStream implementations (squid S4349).

External references: https://errorprone.info/bugpattern/InputStreamSlowMultibyteRead
type : Code Smell ?
tags: performance


(Alexandre Gigleux) #3

Hello Alejandro,

You are right and we need to cover this case. Here is the specification https://jira.sonarsource.com/browse/RSPEC-4929 and its related implementation ticket: https://jira.sonarsource.com/browse/SONARJAVA-2918

Regards