RFR: 8287206: Use WrongThreadException for confinement errors

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed May 25 10:22:49 UTC 2022


On Wed, 25 May 2022 10:16:54 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > Thinking more about it: `IllegalStateException` is fine for a closed `MemorySession`. If used by wrong thread the exception was indeed confusing. Now that the abiguity is gone, I can change our (Lucene) code and just transform every ISE to an already closed in our code. I just wanted to bring up that issue here.
> > PR is here: [apache/lucene#912](https://github.com/apache/lucene/pull/912)
> 
> I've been thinking something similar. I'd suggest to keep the API as is, and maybe revise it at a later point if lack of a specific exception for the "already closed" case proves to be too cumbersome to workaround.

Basically, with this patch you only get ISE if you are accessing _in a moment in time_ when you are not supposed to. Similarly, when calling `close`, you get ISE if you are closing a segment that is in a bad state (e.g. already closed, or temporarily locked by some native call). This feels consistent. The confinement exception was the confounding factor, I think, and a lot of checks against the exception message came from there.

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

PR: https://git.openjdk.java.net/jdk/pull/8865


More information about the nio-dev mailing list