RFR: 8371309: Diagnostic.getEndPosition can throw an NPE with typical broken code

Jan Lahoda jlahoda at openjdk.org
Wed Nov 19 09:02:06 UTC 2025


On Fri, 14 Nov 2025 16:44:43 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> It's my fault for provoking this issue with the commit you referenced - apologies, that change was overly optimistic. I agree the practical answer for now is to add back the null check.
> 
> It makes me wonder if the specified behavior for `Diagnostic.getEndPosition()` was previously being adhered to. It says:
> 
> > offset from beginning of file; `NOPOS` if and only if `getPosition()` returns `NOPOS`
> 
> It seems like more realistic (and accurate) specification would be:
> 
> > offset from beginning of file; `NOPOS` if the ending position is not available
> 
> That's a separate question from this PR of course.

Fixing the JCTree-based JCDiagnostics to never return NOPOS, unless the preferred position is NOPOS:
https://github.com/openjdk/jdk/pull/28316/commits/384fed7243e3322495b3b4cccf13c29d1a23c0df

Thanks!

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

PR Comment: https://git.openjdk.org/jdk/pull/28316#issuecomment-3551559082


More information about the compiler-dev mailing list