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

Andrey Turbanov aturbanov at openjdk.org
Wed Jun 29 21:19:58 UTC 2022


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)

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

Commit messages:
 - [PATCH] Cleanup unnecessary null comparison before instanceof check in java.rmi module

Changes: https://git.openjdk.org/jdk/pull/9332/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=9332&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8289484
  Stats: 9 lines in 3 files changed: 0 ins; 4 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/9332.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9332/head:pull/9332

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


More information about the core-libs-dev mailing list