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
Calling returnData in the release method might result in a NullPointerException in AbstractComponent #204
Comments
Perhaps you could refactor your code like this: Update the WaveType WebcamServiceImpl.CLOSE to send a wave (using the famous voidItem)
Another option would be to use JRebirth.run***Sync methods, but it will be more touchy to do with ServiceTask Does it make the job ? |
In any case I will perform an update to be able to define custom priority when calling attachUi, callCommand and returnData to be sure of the execution order in such cases. I will probably also add a way to force the execution synchronously. These two features will be configured using custom WaveData |
Thanks but this won't work in my case since the webcam might require to be closed without closing the view and releasing the model. So, for the moment I'm using the following workaround :
This way, I'm sure that the release runnable with a priority of low won't be executed before the return data runnable. |
In my code sample the view isn't released the first time but after the callback of your WebcamServiceImpl, so it should work, nevertheless your patch works and you will have to do the inverse when I will add priority management (by adding Priority.High to your returnData call). I will let the possibility to change the release priority too by using a local properties map per component #160. The fix will be based on 8.5.0 version so you will have to upgrade your code, some refactoring have been done and a real modular approach is ready to manage Interface+Implementation. |
I think this is interesting to be able to set a custom priority in the attachUi, callCommand and returnData. However, I'm afraid that it won't be that easy as a developer to anticipate such issues and to know when it will be required to set a custom priority when using these methods. More generally, I think that it would be interesting to improve how JRebirth handle released models : We had several issues related to NPE in JRebirth models and most of the time it was due to the fact that a release model is still trying to use waves or facades, etc... this might happen for example if a model has registered listeners to other components and these listeners are not removed when releasing. Those listeners might still try to use model features when reacting to future events even if the model is released. Would it be possible in all those cases that JRebirth does not fail with an NPE (because the facade or notifier is null) but with a more precise message indicating that the model is released and should not be use anymore ? And maybe to add utilities methods in the Model class helping to register listeners that will be automatically removed when the model is released ? Someting like :
The model could store the registered listeners and remove them on release. What's your opinion about this and how to prevent such cases ? |
The public release method shall be overridden to handle all these custom action. It should be the way when you add custom listeners to a component. |
With 8.5.1-SNAPSHOT Use this sample code
|
We need to call a service when a model is released, so we use the following call in the release method of a model :
The call to returnData will create an AbstractJrbRunnable of priority Normal which will be executed later in the JIT. The call to super.release will also create an AbstractJrbRunnable of priority Normal to be executed in the JIT in order to release the model.
Both runnables are registered in the processingTasks of the JRebirthThread. According to the PriorityBlockingQueue, the order of execution of two tasks with the same priority is not guaranteed :
So it might happen that the release runnable get executed before the runnable submitted by returnData which will fail since getNotifier() of the released component will return null :
The text was updated successfully, but these errors were encountered: