RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base
Aleksei Efimov
aefimov at openjdk.java.net
Tue Dec 15 18:58:07 UTC 2020
On Wed, 2 Dec 2020 20:15:02 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:
>> This seems like a reasonable change, which improves readability.
>>
>> My preference is to wait a little longer (hopefully no more than a couple of weeks), until [JEP 394](https://openjdk.java.net/jeps/394) - "Pattern Matching for instanceof" is finalised, then we can remove the explicit casts in many of these cases. For example:
>>
>> --- a/src/java.base/share/classes/java/io/File.java
>> +++ b/src/java.base/share/classes/java/io/File.java
>> @@ -2191,8 +2191,8 @@ public class File
>> * {@code false} otherwise
>> */
>> public boolean equals(Object obj) {
>> - if ((obj != null) && (obj instanceof File)) {
>> - return compareTo((File)obj) == 0;
>> + if (obj instanceof File file) {
>> + return compareTo(file) == 0;
>> }
>> return false;
>> }
>
> Related issue - https://bugs.openjdk.java.net/browse/JDK-8257448
Hi @turbanoff,
I've logged a JBS issue for tracking this change:
https://bugs.openjdk.java.net/browse/JDK-8258422
JEP 394 is finalized now, so I guess you could follow-up Chris suggestion to remove the explicit casts.
After the fix is properly reviewed and marked as ready for the integration (you'll need to issue `/integrate` command), once it is done I would happily `/sponsor` the change.
With Best Regards,
Aleksei
-------------
PR: https://git.openjdk.java.net/jdk/pull/20
More information about the nio-dev
mailing list