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

Attila Szegedi attila at openjdk.org
Sun Jul 3 20:00:33 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)

Very nice; I specifically like the use of pattern matching for instanceof!

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

Marked as reviewed by attila (Reviewer).

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


More information about the core-libs-dev mailing list