-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Code cleanup & annotations #368
Conversation
I am only building with gradle, so the annotation dependency might need to be added elsewere too. |
I did not realize before that using these features actually requires jdk 7. So: you probably don't want to merge these. I'll revert those changes which would prevent compiling with java 6 asap, so the useful stuff in here can be integrated. |
If you don't like the annotations, tell me. Then I'll remove them from this request. |
Thanks @F43nd1r. I did a couple of little cleanups, but the only thing of note was that several of the ReportSenderFactorys were marked as returning @nullable when they should have been @nonnull. Q: What happens at runtime if a client defies the annotation and passes in a null to a parameter marked @nonnull ? |
These annotations are compile time only. @ nonnull prevents a compile if null is passed and should show a warning when a potentially null parameter is passed. At Runtime this will still result in a Nullpointerexception. Those are meant to help developers preventing Nullpointers beforehand and also allow to use methods correctly without reading sources. (I remember one place where I found a potential Nullpointer in acra and added a check, so at least for that it helps) As I said, most of the annotations were generated automatically (because I haven't read the whole source code). If some of these are wrong, change them. |
Just to clarify, if I annotate a param as @nonnull then a runtime check is made on that param. And a NPE will be thrown if it is null? |
Hmm, that's problematic. I switched the tag for the But if there is no explicit NN check then failure gets deferred to some later point that is a long way from the cause or intent. |
If (and IMO only if) a method can be used as an entry point to the library, it is okay to double check (@ NonNull and if(param == null) ). For this case there is a suppress option. You can see it in use here. I have already added that in the specific place you mentioned in my fork (https://github.com/F43nd1r/acra/blob/master/src/main/java/org/acra/ACRA.java#L189) |
In some places I've replaced Stringbuilders with String concatenation. It is easier to read and the compiler transforms it anyways.
Note: some of these commits where split by hand and might contain data of later / newer commits.