Skip to content
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

Consider using static analysis and formal verification tools #955

Closed
1 task
jbduncan opened this issue Jul 17, 2017 · 31 comments
Closed
1 task

Consider using static analysis and formal verification tools #955

jbduncan opened this issue Jul 17, 2017 · 31 comments

Comments

@jbduncan
Copy link
Contributor

Overview

Currently, AFAICT, no static analysis or formal verification tools are being used to catch bugs in the JUnit 5 code base. IMO it would be a sensible thing to do to start using a combination of various tools now, so that when we reach GA and proceed beyond GA, we are less likely to be inundated by preventable bug reports and/or suffer from potential security issues.

I'd personally suggest a combination of the following tools, but I'm more than happy to discuss the merits of the tools listed and to discuss other tools which aren't listed or that I may have not thought of:

Deliverables

  • A number of agreed-upon static analysis and/or formal verification tools are adopted.
@sormuras
Copy link
Member

Would you mind filing a PR with the tool(s) of your choice?

@jbduncan
Copy link
Contributor Author

No, I wouldn't mind at all!

I'll see if I can find the time later today or this week to submit a PR.

jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 18, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 18, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 22, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 22, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 29, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Jul 29, 2017
@alixwar
Copy link

alixwar commented Aug 7, 2017

SonarQube exists in a cloud version, free for use by Open Source projects: https://about.sonarcloud.io/

SonarQube includes support for PMD, FindBugs and more

@jbduncan
Copy link
Contributor Author

jbduncan commented Aug 7, 2017

@alixwar We could indeed use SonarQube in the future, but I'd feel leery about us primarily depending on it considering that Gradle already comes with first- and third-party support for SpotBugs (FindBugs' current successor), PMD, and other great tools like error-prone.

@jbduncan
Copy link
Contributor Author

jbduncan commented Aug 7, 2017

...and also considering that SonarQube's cloud version is yet another thing which we don't have a lot of control over.

@alixwar
Copy link

alixwar commented Aug 7, 2017

@jbduncan Maybe one solution does not exclude the other? My thinking is that bootstrapping SonarQube (which apparantly now supports SpotBugs as well) is probably very quick and easy (based on my experience setting it up locally). It will have no impact on the code base more than a properties file with some metadata so it can easily be removed if decided so.

@jbduncan
Copy link
Contributor Author

jbduncan commented Aug 7, 2017

You make a good point. I'm most likely dismissing SonarQube out of fear too quickly. :)

I personally have no experience with SonarQube, so it's not something I could setup unless I get a lot of free time and develop the inclination to work on it in the future, so I wouldn't mind at all if you wanted to have a stab at it yourself at some point. :)

@alixwar
Copy link

alixwar commented Aug 7, 2017

I personally have no experience with SonarQube, so it's not something I could setup unless I get a lot of free time and develop the inclination to work on it in the future, so I wouldn't mind at all if you wanted to have a stab at it yourself at some point. :)

Definitely. I can wire it up to a local installation and post some screenshots :)

@alixwar
Copy link

alixwar commented Aug 7, 2017

I have set it up locally. A few comments:

  • I configured it the "Gradle way" which actually means changing the root build.gradle and adding the Gradle SonarQube plugin with config. This is not necessary, although it is the recommended way. The alternative is to use a separate properties file (sonar-project.properties) and analyze the project using an external command line tool (SonarQube Scanner). That way there is no "pollution" to the code base but it will require adding the command tool binary ("SonarQube scanner") to the CI environment and it may not yield as reliable results as the Gradle SonarQube plugin.
  • I had to create empty folders that were missing in some modules (src/main or src/test) for the SonarQube gradle build to complete successfully.
  • I don't have a Clover license locally so I could not report any coverage data. I have configured SonarQube to report from Clover but I cannot test it.
  • I enabled all available rules which might not be what is configured in the cloud version Edit: Apparantly I forgot to start using the "All rules" profile... So this is with the default rules enabled.
  • A good (essential imo) thing with SonarQube is that you have seamless integration with some IDEs (using the SonarLint plugin that exists for Eclipse and IntelliJ).

Some sceenshots (dashboard, list of issues and viewing the details of an issue):

dashboard
issues
example-issue

@alixwar
Copy link

alixwar commented Aug 7, 2017

New screenshots with all rules applied:

dashboard-2
issues-2
example-issue-2

@alixwar
Copy link

alixwar commented Aug 7, 2017

Some screenshots from IntelliJ:

intellij-config
intellij-issue-in-code

@alixwar
Copy link

alixwar commented Aug 7, 2017

Here are the changes: #1008

@alixwar
Copy link

alixwar commented Aug 10, 2017

@jbduncan @sormuras Anything else you want to know about SonarQube and its capabilities?

@sormuras
Copy link
Member

Thanks for all your work @alixwar and @jbduncan in this section!

Given the amount of time left for RC3 (and higher) and especially for GA, static code analysis might not find it's way into this project's automated build process in the near future. As far as I can see from your manually executed runs and screenshots, there's no show-stopper found in the JUnit 5 code base that would prevent a release. Do you agree?

@alixwar
Copy link

alixwar commented Aug 10, 2017

There are some (9) violations concerning optionals being retrieved without a "Optional#isPresent()" check.
Example:

RepeatedTest repeatedTest = AnnotationUtils.findAnnotation(testMethod, RepeatedTest.class).get();

I'm not familiar with the code so I don't know whether this is a show stopper.

@sormuras
Copy link
Member

IIRC, those un-guarded Optional.get() calls are all located in our test cases. Here, a failing .get() would result in a failing test. Which is okay for me.

@alixwar
Copy link

alixwar commented Aug 10, 2017

Then I'm not aware, at least, of a show stopping issue. But it is a good thing to have static code analysis set up ASAP to avoid building up debt

@jbduncan
Copy link
Contributor Author

jbduncan commented Aug 10, 2017

@alixwar I actually do have a question regarding SonarQube, thanks for asking.

In one of your IntelliJ screenshots above, it shows "violations" like "move left curly brace one line ahead" and "convert tabs to spaces". Although I personally agree with spaces, the JUnit team decided on tabs a long time ago, and they also decided on placing left curly braces as they currently are, so is there a way of telling SonarQube to not report cases like this?

@jbduncan
Copy link
Contributor Author

@sormuras It's a pleasure! :)

jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 22, 2017
@alixwar
Copy link

alixwar commented Aug 22, 2017

@jbduncan @sormuras This add-on might save some time for reviewing pull requests: https://docs.sonarqube.org/display/PLUG/GitHub+Plugin

@sormuras
Copy link
Member

Indeed. Looks nice and clean.

jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 22, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 22, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 23, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 23, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 24, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Aug 25, 2017
@marcphilipp marcphilipp modified the milestones: 5.0 GA, 5.1 Backlog Sep 7, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Sep 8, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Sep 29, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Sep 30, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Oct 6, 2017
jbduncan added a commit to jbduncan/junit5 that referenced this issue Oct 13, 2017
@smoyer64
Copy link
Contributor

Related to #358.

@pauldingemans
Copy link

pauldingemans commented Feb 16, 2020

In pull request #1008 an implementation of SonarQube was set up.

Finally the team decided not to merge it to master.

Does it also mean that this issue should be closed or should it be kept open waiting for an alternative?

@sbrannen
Copy link
Member

Does it also mean that this issue should be closed or should it be kept open waiting for an alternative?

This issue will remain open for the time being. The JUnit 5 team is open to alternative solutions but primarily for simple solutions that provide real value to the team. The terms "simple" and "real" are of course left to interpretation by the team itself.

@stale
Copy link

stale bot commented May 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label May 13, 2021
@jbduncan
Copy link
Contributor Author

I'm happy to close this issue, actually. I've learned since opening it that a judicious use of static analysis tools is the best kind of use.

I still quite like error-prone though. ;)

And if SonarQube is ever deemed useful in the future, a new issue could easily be opened there and then.

@marcphilipp marcphilipp removed this from the 5.x Backlog milestone May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants