All of these instanceof checks can also take advantage of Java 17's pattern matching instanceof operator. Related: #1326.