Use java 15 pattern matching instanceof

Comment From: philwebb

Thanks very much for the pull-request, unfortunately we're not yet ready to accept Java 17 updates. We're tracking this one in #28181 which is currently marked as blocked. If you're happy to leave your pull-request branch around it might be helpful for us when we do get around to the issue.