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
Add optional org.eclipse.jdt.annotation dependency to binding bundles #2556
Conversation
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
I noticed that some |
What is the story about this change? |
Are you refering to build error such as reported here? It is an Eclipse JDT Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=463359 The story behind that is we introduced null annotations ins ESH and also placed them in some Generics, such as Usually the Eclipse JDT compiler should inherit this EDIT: And this change is "just" about making the IDE aware of these null annotations on the binding bundles, so the null checks are executed inside the IDE. I just have to find out what's different for ESH and OH why the |
|
Personally I would expect such annotations (especially on Generics) only to be needed at compile time and not at runtime, is the manifest really the proper place to add it? |
Having it as an optional dependency in the Also the Eclipse documentation says we should include it as an optional |
Only one thing remains, can you look into and fix the builds for this PR? |
@martinvw Just ftr as this probably escaped you - the full discussion around that feature was done here: eclipse-archived/smarthome#3624 |
Problem is here: openhab/openhab-core#189 Edit: Together with this one: eclipse-archived/smarthome#4046 So I am not sure if Travis builds against the current ESH master or snapshot? If it builds against a snapshot it will still fail, because we need this |
close/reopen to re-trigger travis build EDIT: Yay, passed Travis build |
@@ -14,6 +14,7 @@ Bundle-NativeCode: lib/x86-64/win/alljoyn_java.dll;processor=amd64;osname=win32; | |||
lib/arm/linux/liballjoyn_java.so;processor=arm;osname=linux,* | |||
Import-Package: com.google.common.collect, | |||
org.apache.commons.io, | |||
org.eclipse.jdt.annotation;resolution:=optional, |
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.
Is this now required for every bundle should I refuse bindings without this?
Should we add static analysis for this?
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.
The new archtype that will be released with the next ESH stable release already includes this as a default, see here. So please refuse bindings without this dependency.
A static analysis would be nice to have, yes. In the end it is a benefit for the developers as they get a direct warning in there IDE if they pass a null
value to a @NonNull
parameter of a method for example.
With default non nulls, what is the recommendation for handling fields that should be non-null but are initialized using functions not suited for null annotations, for example:
There will be a mismatch that toLowerCase() may return null, so it can't be assigned to this string. I could check this null before I assign it, but there is nothing else I could assign to the string, this seems not right. I don't want to make this variable nullable too, as it should be nonnull and I'd like to rely on toLowerCase to never be null. |
As long as we do not have external annotations for libraries such as the JDK you can suppress the warning like Kai suggested here: eclipse-archived/smarthome#3930 (comment) |
I have the following error which I find to hard correctly categorize is it a false positive or a missing annotation in the framework:
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;
} Because of the call to |
I started moving my binding code to non-null by default. Already removed many redundant checks and dead code parts. Also, use of Optional results in not only safer code, but the methods that come with Optional allow for more esthetic and simpler code. I am very pleased with the results and hope to finish it soon.
Error is at Collection: And compiler suggests to change the definition of the interface (no combination of nullable at implementation gets rid of this error). Any ideas how to overcome this?
|
I think there is an annotation missing in the Thing class because a thing should always have a UID. @ppieczul Regarding the use of The ChannelTypeProvider does not have any annotations, so how can you get a warning regarding the null annotations if you implement it? Can you please give an example? @ppieczul Regarding your last example: The static code analysis from Eclipse to check these null annotations is for sure not 100% fail safe and will generate false positives. Why it does that in this case I honestly don't know. But using external annotations, especially to annotate JDK code would be helpful, I agree. Does anyone have an idea how to use them and also where to get a annotations for the JDK so we do not have to do that again manually? |
There's one more interesting case with maps. Because map.get() get return null when key is not found, the correct definition of maps is: |
…openhab#2556) Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
…openhab#2556) Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
…openhab#2556) Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
Signed-off-by: Stefan Triller stefan.triller@telekom.de