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 RV_RETURN_VALUE_IGNORED_BAD_PRACTICE SpotBugs violations #6025

Merged
merged 10 commits into from
Dec 11, 2021

Conversation

basil
Copy link
Member

@basil basil commented Dec 7, 2021

Fixes most RV_RETURN_VALUE_IGNORED_BAD_PRACTICE, mostly by switching to NIO.2 where possible.

Proposed changelog entries

N/A

Proposed upgrade guidelines

N/A

Submitter checklist

  • (If applicable) Jira issue is well described
  • Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    • Fill-in the Proposed changelog entries section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@StefanSpieker

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are correct
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@basil basil added the skip-changelog Should not be shown in the changelog label Dec 7, 2021
@basil basil force-pushed the RV_RETURN_VALUE_IGNORED_BAD_PRACTICE branch 3 times, most recently from 50bc009 to c6814e9 Compare December 8, 2021 22:42
@basil basil mentioned this pull request Dec 9, 2021
@basil basil force-pushed the RV_RETURN_VALUE_IGNORED_BAD_PRACTICE branch from c6814e9 to d0f5060 Compare December 9, 2021 03:01
@basil
Copy link
Member Author

basil commented Dec 9, 2021

This PR was tested successfully in a passing Windows CI run in #6036.

@basil basil added the squash-merge-me Unclean or useless commit history, should be merged only with squash-merge label Dec 9, 2021
basil added a commit to basil/bom that referenced this pull request Dec 9, 2021
@basil
Copy link
Member Author

basil commented Dec 9, 2021

This PR was tested successfully in a passing BOM run in jenkinsci/bom#757.

@basil basil requested a review from a team December 9, 2021 22:15
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—long overdue! Some places I think we wanted to recover gracefully rather than throwing an exception (but silently ignoring the error was bad).

core/src/main/java/hudson/PluginManager.java Outdated Show resolved Hide resolved
core/src/main/java/hudson/WebAppMain.java Outdated Show resolved Hide resolved
try {
Files.deleteIfExists(file.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just log instead? I do not think callers would be expecting an unchecked exception here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few lines above, we convert IOException into Error, so I feel like all bets are off with this code path. I made both that path and this one throw UncheckedIOException, as at least that seems better than Error.

@@ -1882,12 +1883,8 @@ protected void _run() throws IOException, InstallationStatus {
*/
protected void replace(File dst, File src) throws IOException {
File bak = Util.changeExtension(dst,".bak");
bak.delete();
dst.renameTo(bak);
dst.delete(); // any failure up to here is no big deal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: behavioral change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this seemed like more straightforward behavior to me.

src/spotbugs/spotbugs-excludes.xml Show resolved Hide resolved
src/spotbugs/spotbugs-excludes.xml Outdated Show resolved Hide resolved
Comment on lines +253 to +254
public void mkdirs() throws IOException {
Files.createDirectories(Util.fileToPath(file.getParentFile()));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically an API change, but there are no plugin consumers of this API, and all the consumers in core were already throwing IOException anyway.

Comment on lines +60 to 62
public void delete() throws IOException {
Files.deleteIfExists(Util.fileToPath(file));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically an API change, but there are no plugin consumers of this API, and all the consumers in core were already throwing IOException anyway.

Comment on lines +249 to 251
public void delete() throws IOException {
Files.deleteIfExists(Util.fileToPath(file));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically an API change that affects 7 plugins at compile-time, but I don't think the addition of the throws should affect those seven plugins at runtime. I think this is probably fine, but if people feel strongly otherwise I can convert this to an UncheckedIOException in order to preserve the existing method signature for those 7 plugins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which plugins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jglick Did you have any opinion about this part? This is what I'm the most unsure about, so would be good to hear if you think this is OK or if you'd prefer the UncheckedIOException approach here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine—may cause a compilation error on upgrade, but trivially resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyartifact
ecutest
gerrit-trigger
google-container-registry-auth
jqs-monitoring
nodejs
nuget
xvfb

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not do a very close review but looks good.

@basil basil requested a review from jglick December 10, 2021 20:45
basil added a commit to basil/copyartifact-plugin that referenced this pull request Dec 10, 2021
basil added a commit to basil/copyartifact-plugin that referenced this pull request Dec 10, 2021
basil added a commit to basil/xvfb-plugin that referenced this pull request Dec 10, 2021
@basil
Copy link
Member Author

basil commented Dec 11, 2021

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process. Thanks!

@basil basil added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Dec 11, 2021
@basil basil merged commit 165d559 into jenkinsci:master Dec 11, 2021
@basil basil deleted the RV_RETURN_VALUE_IGNORED_BAD_PRACTICE branch December 11, 2021 20:51
zregvart added a commit to jenkinsci/xvfb-plugin that referenced this pull request Dec 13, 2021
ikedam added a commit to jenkinsci/copyartifact-plugin that referenced this pull request Dec 19, 2021
Compatibility with jenkins-2.325 and later (jenkinsci/jenkins#6025)
@@ -96,7 +96,7 @@ public String read() throws IOException {
* Overwrites the file by the given string.
*/
public void write(String text) throws IOException {
file.getParentFile().mkdirs();
Files.createDirectories(Util.fileToPath(file.getParentFile()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess createDirectories was meant here?

basil added a commit to basil/bitbucket-branch-source-plugin that referenced this pull request Aug 8, 2022
lifeofguenter pushed a commit to jenkinsci/bitbucket-branch-source-plugin that referenced this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog squash-merge-me Unclean or useless commit history, should be merged only with squash-merge
Projects
None yet
4 participants