-
Notifications
You must be signed in to change notification settings - Fork 145
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
New check: Jsr305Annotations #734
Comments
Existing PR is here: #728 |
@rnveach, I am ok to host such Check in our project. Please review and approve issue, to start PR acceptance process. |
My only concern is if this check might be doing too much in 1 place and if it could be broken up somehow. PR code is 1000 lines. @romani Also what package should this check be in? PR currently has it in it's own custom package and not one of our standard locations. |
We should run it with ignore severity. We are not ready to use that approach in design.
I would avoid extra packages. I think better place is coding package
We will keep it's name, so it far from generic, so let it do what it does now. While it is in sevntu, I am a bit relaxed on demands. I have no time to make deep analysis of that Check and propose better design. So I am ok to keep it as is, with demand to follow our quality gate. |
I'm fine with that. I will prepare a new PR with the code living in the coding package. Since I already have feedback from the CI I'll also look into the test coverage wich was still a bit too low. |
thanks a lot, please also run your Check by https://github.com/checkstyle/contribution/tree/master/checkstyle-tester to generate report over all projects and make sure your Check does not have exception at least. |
OK. Bear with me. I'm currently working on the test coverage which is going to take a while (you know, those damn last 5%). |
Oh, yes, we know, in main project we demand even mutation 100%, so in sevntu we are relaxed a bit. |
Since this is sevntu, he has limited regression support since groovy doesn't support sevntu. If your feeling adventurous you can try using the shell scripts: https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/sevntu_launch_diff.sh and https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/launch_diff_variables.sh |
Thank you. I have finished pimping the tests. The vast majority is on input files, but I have also implemented some classic unit tests. |
Yes, I've read that part about checkstyle-tester. I haven't really started yet. If you've got any additional information that could speed up the process this would help a lot. |
@mbert If you need additional help, just point out what you need in the PR and we will try to help as best we can. |
I will try to get a run with the checkstyle-tester today or tomorrow (depends on project load here). I have also created an example project that I would upload to this issue. It is annotated the way we want to enforce it with the plugin, also it uses the sevntu maven plugin from a preceding "mvn clean install" with the fresh code. Once I have finished with the checkstyle-tester and found that no more amendmends to the code seem necessary from my side I'll upload the PR and the sample project. Sounds OK? |
sounds fine to me. |
I don't seem to understand how to run the checkstyle-tester correctly. I'm running it like this:
I edited
According to the docs ("Sevntu can only be run with patch only branch and config.") I am using only a patch branch and a config argument - which seems to make sense because there's nothing to diff against when there are no changes in the Can you give me a quick hint how to run this properly? |
OK, I've (kind of) helped myself now by creating a branch in the checkstyle repo which is identical to In the index.html file there are lots of warnings emitted by the new check which is to be expected of course. So that result seems fine, right? |
Here's an annotated example project. To try out the new check, the following steps are required:
|
Now I've got the first CI feedback. That was a new one to me. There's a number of PMD failures, most of them however on the 'test object' java files used by the unit test (i.e. code that is never executed). Would excluding them from the check be acceptable? If yes, how? Also the test class I have fixed the PMD warnings from the check's main class. Waiting for feedback on my above comments for the test code. |
…D use in tests needs to be discussed in sevntu-checkstyle#734 and/or elsewhere)
@mbert Anything related to the implementation, lets discuss in the PR so we don't have 2 split conversations going on.
If your files are input files to tests, they should go under
It must be |
Ah, good to know. Will fix that next Monday. And then let's see what remains.
Also good to know. Is the result I have produced using my little workaround relevant, or should I rerun it? |
It looks you just gave us the results of what is in the patch directory. When groovy is done, there is a directory named |
OK, here's what's in the |
…esources as required, fixed more PMD issues
…ditional Javadoc
…ent in pom.xml, examples in Javadoc, contributors' list in README.textile
…D use in tests needs to be discussed in sevntu-checkstyle#734 and/or elsewhere)
…esources as required, fixed more PMD issues
…est and remove remaining PMD errors
…om travis build
…ditional Javadoc
…ent in pom.xml, examples in Javadoc, contributors' list in README.textile
…ncreased test coverage, required javadoc
fix is merged |
The Jsr305 annotations (annotations for software defect detection) contain a subset of "nullness" annotations that can be used to mark parameters as possibly null (
@Nullable
) or always non-null (@Nonnull
), function return values as to be checked for null (@CheckForNull
) or always non-null (@Nonnull
) including defaults on class level (@ParametersAreNonnullByDefault
,@ParametersAreNullableByDefault
,@ReturnValuesAreNonnullByDefault
).Using these annotations a programmer can declare how the code is meant to behave, and static code analysis (like e.g. FindBugs) can be used to verify that this is actually true. Also these annotations help others understanding code more easily, e.g. if confrontend with an annotated interface the necessity for null checks can easily be deducted from the annotations.
The Jsr305AnnotationsCheck supports enforcing the following code style:
void
or anint
can never be null anyway).@Nonnull
annotation is always illegal because being less "nullable" cannot be assumed for a parameter in an inherited method. Conversely@Nullable
is always allowed. For return values it is the other way round:@CheckForNull
is always illegal while@Nonnull
is always legal.Here are a few examples:
The rules for treating inherited methods' return values and parameters can be relaxed, which can be useful for transitional periods when introducing this check to existing code. Having set the properties
allowOverridingReturnValue
andallowOverridingParameter
totrue
, in the example above all method definititions forClass3
will be legal.To get a fuller picture of the possible warnings and the corresponding code, I have appended the test classes from the check's unit test (they are also in the PR). This is the output the check generates for them:
jsr305-test-files.zip
The text was updated successfully, but these errors were encountered: