RFR: 8348906: InstanceOfTree#getType doesn't specify when it returns null

Chen Liang liach at openjdk.org
Tue May 13 22:51:55 UTC 2025


On Tue, 13 May 2025 11:29:11 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> `InstanceOfTree.getType()` returns `null` if the `instanceof` uses a pattern different than the type test pattern. This is not documented, and should be documented. This PR proposes the documentation for this.
> 
> Alternatively, we could change `getType()` to return a type for other types of patterns, but the meaning of that is not quite clear even for record patterns, and it gets even less clear with the possible future patterns. I believe it has been mostly a conscious decision to not handle record patterns in this method. Possibly, it was a mistake to handle the type test/binding patterns in `getType()`, but that's not something that we should change, I think.
> 
> Please also review the CSR:
> https://bugs.openjdk.org/browse/JDK-8356857

We should also update the examples on `InstanceOfTree` itself and `getPattern` to indicate all three possibilities we have right now for (type, pattern) - at least one of these is non-null.

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

PR Comment: https://git.openjdk.org/jdk/pull/25205#issuecomment-2878129058


More information about the compiler-dev mailing list