RFR: 8299513: Cleanup java.io

Alan Bateman alanb at openjdk.org
Wed Jan 4 16:38:50 UTC 2023


On Wed, 4 Jan 2023 15:54:29 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

>> Code in java.io contains many legacy constructs and semantics not recommended including: 
>> 
>> * C-style array declaration 
>> * Unnecessary visibility 
>> * Redundant keywords in interfaces (e.g. public, static) 
>> * Non-standard naming for constants 
>> * Javadoc typos 
>> * Missing final declaration 
>> 
>> These should be fixed as a sanity effort.
>
> src/java.base/share/classes/java/io/StringWriter.java line 244:
> 
>> 242: 
>> 243:     private static int checkSize(int initialSize) {
>> 244:         if (initialSize < 0) {
> 
> Similar checks exist e.g. in `ByteArrayOutputStream` and `CharWrite`, so could we reuse it somehow across java.io?

I assume this is done so that "lock" is only set once during construction (StringWriter is a bit unusual in that it uses the SB as the lock object). A downside of the change is that it introduces casts. Another is that the expression to super is a bi  complicated and forces the reader to locate checkSize at the end of the file to find the code specified by the constructor. So two minds on this part, maybe it should be left unchanged.

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

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


More information about the core-libs-dev mailing list