JetBrains / JetBrainsRuntime

Runtime environment based on OpenJDK for running IntelliJ Platform-based products on Windows, macOS, and Linux
GNU General Public License v2.0
1.26k stars 192 forks source link

JBR-6771 BoxLayout throws mysterious NPEs due to previous exceptions #326

Closed stachenov closed 4 months ago

stachenov commented 5 months ago

This isn't really a bug, more like an inconvenience that masks real bugs.

The checkRequests method only does layout initialization if it isn't initialized already. However, when an exception is thrown during the initialization, the layout may end up in a half-initialized state.

Fix this by using the field that is initialized the last to check if the layout is initialized. If that field is null, it may mean that the layout isn't initialized or that the last attempt failed midway. Then we try again. This attempt can, of course, break for the same reason as the previous one, but in that case we'll at least get a stack trace pointing to a real cause of the error and not some mysterious NPE that seems to be impossible from the logic.

mkartashev commented 4 months ago

Merged into main, jbr21, jbr17.