-
Notifications
You must be signed in to change notification settings - Fork 787
Question: Missing @NonNull in Thing.getThingTypeUID() #4099
Comments
No, to my understanding Thing Types are optional - i.e. they can (and most of the time will) be used as prototypes to describe a thing, but could be omitted completely when describing Things manually. |
Then our archetype is wrong and should be throwing NPE's as well: @maggu2810 @kaikreuzer wdyt? |
Independent of that, it would be the better (in the sense of defensive) style anyway to turn it around, i.e. if (THING_TYPE_SAMPLE.equals(thingTypeUID)) {
return new ${bindingIdCamelCase}Handler(thing);
} |
I don't know who is currently using things without a type, but it could be possible (if this is an officially supported feature). |
@maggu2810 I agree that the change of @SJKA is a good one and should be done but my question started out from the following warning and code snippet:
Fragment: @Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (RFXComBindingConstants.SUPPORTED_BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID)) {
RFXComBridgeHandler handler = new RFXComBridgeHandler((Bridge) thing);
registerDeviceDiscoveryService(handler);
return handler;
} else if (supportsThingType(thingTypeUID)) {
return new RFXComHandler(thing);
}
return null;
} We are not allowed to pass null to |
If
I assume you should return @Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID == null) {
// We don't support things without a specific thing type UID
return null;
}
if (RFXComBindingConstants.SUPPORTED_BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID)) {
RFXComBridgeHandler handler = new RFXComBridgeHandler((Bridge) thing);
registerDeviceDiscoveryService(handler);
return handler;
} else if (supportsThingType(thingTypeUID)) {
return new RFXComHandler(thing);
}
return null;
} |
So my main question remains:
@kaikreuzer wdyt? |
@SJKA Is right that it used to be an official feature of the originally designed architecture. Nonetheless, in practise this has never been used/supported by any binding and as such it got out of sight. |
Just to be sure, a PR could exist of adding the annotation and making sure that no other errors happen because of the added annotation? |
Give it a try ;-) |
With the new guidelines that @triller-telekom created, I am afraid that the solution to this issue now looks pretty different - feel free to come up with a new PR that updates the |
Fixes eclipse-archived#4099 Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Fixes #4099 Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
As discussed with @triller-telekom https://github.com/openhab/openhab2-addons/pull/2556#issuecomment-323672397
@triller-telekom and me think
@NonNull
annotation is missing on getThingTypeUID do you agree?The text was updated successfully, but these errors were encountered: