-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
[config] Enable config validation for updates by handler #2712
[config] Enable config validation for updates by handler #2712
Conversation
Signed-off-by: Jan N. Klug <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the slight feeling that this will it work because the BaseThingHandler:: update configuration ()
methods replaces the configuration properties before calling the updateThing()
methods on the callback.
Lines 425 to 434 in 16bc932
this.thing.getConfiguration().setProperties(configuration.getProperties()); | |
synchronized (this) { | |
if (this.callback != null) { | |
this.callback.thingUpdated(thing); | |
} else { | |
logger.warn( | |
"Handler {} tried updating its configuration although the handler was already disposed.", | |
this.getClass().getSimpleName()); | |
} | |
} |
Meaning the wrong parameters will be applied even if you discard the changes later.
...ore.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java
Show resolved
Hide resolved
...ore.thing.tests/src/main/java/org/openhab/core/thing/binding/BindingBaseClassesOSGiTest.java
Show resolved
Hide resolved
I reworked that. Now the Do you think |
Signed-off-by: Jan N. Klug <[email protected]>
...es/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/BaseThingHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Jan N. Klug <[email protected]>
No, I don't think so. Do you see a specific reason for doing it? |
After checking the code: no. I was wondering if it is possible to change configuration with |
If you are afraid that we loose this safety check by overridden methods we can try to move it deeper into the framework. E.g. into the |
But then we are back where we were before: the wrong config is applied before it is validated. I think that overriding |
Let's add a note about that to the JavaDoc. This way people know what the method is doing and what to take care of if they override it. |
Signed-off-by: Jan N. Klug <[email protected]>
Done |
Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: Jan N. Klug <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
* Enable config validation for updates by handler Signed-off-by: Jan N. Klug <[email protected]> GitOrigin-RevId: 61f5e7f
See #2682 (comment)
It was assumed that thing handlers only update valid configuration. After merging #2682 it was discovered that this is not true. This PR enables the same validation for updates through the handler. If an invalid configuration or otherwise illegal (not-initializable) thing is detected, the changes are discarded and a warning logged.
Signed-off-by: Jan N. Klug [email protected]