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

Fix spotbugs errors #794

Merged
merged 17 commits into from
Apr 25, 2020
Merged

Fix spotbugs errors #794

merged 17 commits into from
Apr 25, 2020

Conversation

pjdarton
Copy link
Member

@pjdarton pjdarton commented Apr 24, 2020

This plugin's pom says not to fail if spotbugs finds problems; that's not good.
This PR fixes those issues through a series of commits.

FAO anyone merging these changes:

  1. This is going to be painful; there's a lot of changes in here.
  2. I'd suggest you might want to merge (or rebase) one commit at a time.

I've tried to keep the commits fairly self-contained, with each one addressing one thing or one theme at a time but there were mistakes made during the commital phase where e.g. code changes went into an earlier commit than the imports it depended on.
The unit tests only passed on the final build, but that's mainly because DockerNodeStepTest is unstable on the jenkinsci build server (but works fine locally). Code was added (in the last commit) to attempt to address that, but it's still not stable.

A summary of the functional changes is as follows:

  • When persisting data, we now store nulls instead of empty fields, reducing unnecessary clutter in the resulting XML.
  • DockerBuilderControlOptionStop now stops containers when told to
  • Don't use platform default encoding, use UTF-8 or US-ASCII.
  • Logging improvements so we don't suppress as many exceptions as we used to
  • SpotBugs will now fail the build if issues are found.
  • In many situations where a NullPointer exception would've been thrown, you'll now get an IllegalArgument or IllegalState instead.

Fixed spotbugs error: Removed Clonable declaration from classes that
didn't use it and/or didn't implement it.
@pjdarton pjdarton added the WIP PR that is *not* ready for merging (but hopefully being worked on by the author). label Apr 24, 2020
pjdarton added 16 commits April 24, 2020 11:54
Bugfix: Removed Serializable declaration from classes that contain
non-serializable fields.
Added serialVersionUID to classes that need it.
Removed serialVersionUID from classes that didn't need it.
Fixed spotbugs error: transient field not set by deserialization
Bugfix: DockerNodeStep's connector has to be Serializable.
Renamed properties in Messages.properties to fit with naming
conventions.
Local variables shouldn't start with a capital letter.
We use UTF-8 unless we're sure US-ASCII will suffice.
Enhancement: Where possible, store nulls instead of empty
strings/collections.
Code improvement: Added @CheckForNull/@Nullable/@Nonnull/@deprecated
annotations to aid clarity.
Refactor: Moved String split/filter/trim methods to JenkinsUtils class.
Null-proofed code.
Unified the two methods of parsing a volumes string within
DockerTemplateBase to one common method used for both processing and
validation.
DockerComputerAttachConnector text hard-coded name of java and the jvm
args.
Now the help reads these from the code so they can't get out of step.
Found by spotbugs error: DockerBuilderControlOptionStop didn't remove
containers when it was told to - it didn't exec the removal.
- Added @restricted(NoExternalUse.class) to code that shouldn't be used
outside the plugin.
- Made some classes/methods static where possible.
- Made some things less visible where possible.
Fixed some potential null-pointer exceptions.
Removed redundant null checks.
Removed unnecessary code.
Remove unnecessary cast.
Fix inefficient use of boxing.
Sometimes spotbugs gets it wrong.
Sometimes spotbugs is right but it isn't a problem in practise and it's
not worthwhile trying to fix it.
Eclipse complains about an unnecessary cast and wants it gone.
My local build doesn't complain either way.
JenkinsCI fails to compile without the cast.
Make sure subsequent builds insist on a clean result.
@pjdarton pjdarton merged commit a3b950e into master Apr 25, 2020
@pjdarton pjdarton deleted the code_cleanup branch April 25, 2020 02:15
@pjdarton pjdarton added bug An issue reporting a bug or a PR fixing one. build Changes unrelated to functionality, e.g. build code. and removed WIP PR that is *not* ready for merging (but hopefully being worked on by the author). labels Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue reporting a bug or a PR fixing one. build Changes unrelated to functionality, e.g. build code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant