RFR: 8289484: Cleanup unnecessary null comparison before instanceof check in java.rmi

Jaikiran Pai jpai at openjdk.org
Thu Jun 30 01:51:32 UTC 2022


On Wed, 29 Jun 2022 21:11:09 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> Update code checks both non-null and instance of a class in jdk.hotspot.agent module classes.
> The checks and explicit casts could also be replaced with pattern matching for the instanceof operator.
> 
> For example, the following code:
> 
>         if ((obj != null) && (obj instanceof TCPEndpoint)) {
>             TCPEndpoint ep = (TCPEndpoint) obj;
>             if (port != ep.port || !host.equals(ep.host))
> 
> Can be simplified to:
> 
>         if (obj instanceof TCPEndpoint ep) {
>             if (port != ep.port || !host.equals(ep.host))
> 
> 
> See similar cleanup in java.base - [JDK-8258422](https://bugs.openjdk.java.net/browse/JDK-8258422)

Looks good to me.

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

Marked as reviewed by jpai (Reviewer).

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


More information about the core-libs-dev mailing list