-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI.getCurrent() is null in ErrorHandler #10533
Comments
Reminds me of #9971 |
This is not a bug, it just means that you need to setup your
|
I disagree. In my eyes I'd expect error handler to run in the ui thread since it will most probably notify the user of the error via some ui call. It does not which is unexpected, not clarified via a documentation and therefore a bug. The current solution's behavior is mysterious:
The example code is broken for scenario when you have more than one UI (unlikely but possible). In such case, your code will notify just one random ui, since the error handler is session-scoped and the UI init listener will overwrite the error handler set by the previous UI init listener. |
This is exactly a duplicate of #9971 which is marked as a bug as I would not claim that "the way it is coded is good enough" but this issue can be about fixing the documentation+javadocs and the other issue about fixing the problem by changing the behavior. And I think the the workaround in #10533 (comment) is bad but #9971 (comment) should work instead. |
It doesn't if there are multiple UI instances (multiple tabs). Regardless, it's Vaadin's job to properly fill in the current UI. |
I would say that current API is a bit bad with that respect. One approach to make API better would be to move setErrorHandler in UI init handler instead of setting it for service. That would need some refactorization and naturally would be breaking change ... Thus I guess requires careful design. Also one should decide what to do with old setErrorHandler method. Whether it should be just marked depracted with notes why, or should it be rendered to no operation state. |
No need - far simpler is to make Vaadin to fill in the current UI correctly. Vaadin KNOWS the UI, it's just not passing it in. |
It is not that simple. Sevice - UI is one to many mapping when there are multiple browser tabs. |
That is true, but Vaadin can simply remember the UI instance in the |
* chore: add test testing for correct UI.current instance in ErrorHandler * fix: Sets the current UI to this before calling ErrorHandler. Fixes #10533 * chore: star import * chore: star import * refactoring: use CurrentInstace to preserve current UI
* chore: add test testing for correct UI.current instance in ErrorHandler * fix: Sets the current UI to this before calling ErrorHandler. Fixes #10533 * chore: star import * chore: star import * refactoring: use CurrentInstace to preserve current UI
Throwing an exception in the
ui.access()
block from bg thread will callErrorHandler.error()
withUI.getCurrent()
set to null. That will fail to show any notification from theErrorHandler
with the following stacktrace:The
ErrorHandler
does not document whether it's called in Vaadin UI thread or not. If it doesn't, this needs to be clearly documented. If yes, then the Vaadin environment should be set properly - the UI.getCurrent() should not return null. In either case, this needs to be documented in theErrorHandler
javadoc.Minimal reproducible example
Attaching the skeleton starter app which demoes the issue. In short, this view demoes the issue:
Make sure to have the ErrorHandler set; wait for 1 second then check out the console log.
skeleton-starter-flow.zip
Expected behavior
The UI.getCurrent() should not be null.
Actual behavior
The UI.getCurrent() is null.
Versions:
The text was updated successfully, but these errors were encountered: