RFR: 8267329: Modernize Javadoc code to use instanceof with pattern matching [v3]

Ian Graves igraves at openjdk.java.net
Wed May 19 19:22:40 UTC 2021


On Wed, 19 May 2021 17:24:44 GMT, Jonathan Gibbons <jjg at openjdk.org> wrote:

>> Ian Graves has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Name shortening. Copyright updates.
>
> src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkOutputImpl.java line 54:
> 
>> 52:     @Override
>> 53:     public void append(Object o) {
>> 54:         output.append(o.toString());
> 
> There may be a change in behavior here, for "invalid" arguments, which will now use `.toString()` instead of throwing CCE.

My first reaction is in agreement, but upon further inspection it seems that this class is not used by anything in the module. Interestingly its documentation header warns not to rely on its behavior to remain the same.

> src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/ContentBuilder.java line 72:
> 
>> 70:             } else {
>> 71:                 contents.add(tb = new TextBuilder());
>> 72:             }
> 
> Restructure this
> 
> contents.add((c instanceof TextBuilder tb) ? tb : new TextBuilder());
> 
> or something similar

Unclear if there's a more succinct way to refactor this like so. If `c` is not an instance of `TextBuilder` then we need to initialize a new `TextBuilder` and add it to `contents`. This is not the case if `c` is already of the desired instance.

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

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


More information about the javadoc-dev mailing list