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

Increase spotbugs checks #1475

Merged
merged 4 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<!-- https://stackoverflow.com/questions/12038238/unable-to-locate-source-xref-to-link-to -->
<linkXRef>false</linkXRef>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Medium</spotbugs.threshold>
<spotbugs.threshold>Low</spotbugs.threshold>
</properties>

<dependencyManagement>
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -958,10 +958,6 @@ private static StandardUsernameCredentials lookupScanCredentials(@NonNull Run<?,
}
}

private static CredentialsMatcher gitScanCredentialsMatcher() {
return CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class));
}

@NonNull
private BuildData fixNull(BuildData bd) {
ScmName sn = getExtensions().get(ScmName.class);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonN
target = target.substring(Constants.R_HEADS.length());
}
List<Action> result = new ArrayList<>();
if (target != null && !target.isBlank()) {
if (!target.isBlank()) {
result.add(new GitRemoteHeadRefAction(getRemote(), target));
}
return result;
Expand All @@ -1159,7 +1159,7 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonN
target = target.substring(Constants.R_HEADS.length());
}
List<Action> result = new ArrayList<>();
if (target != null && !target.isBlank()) {
if (!target.isBlank()) {
result.add(new GitRemoteHeadRefAction(getRemote(), target));
}
return result;
Expand Down Expand Up @@ -1188,7 +1188,7 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonN
target = target.substring(Constants.R_HEADS.length());
}
List<Action> result = new ArrayList<>();
if (target != null && !target.isBlank()) {
if (!target.isBlank()) {
result.add(new GitRemoteHeadRefAction(getRemote(), target));
}
return result;
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/jenkins/plugins/git/GitToolChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,15 @@ private boolean setSizeFromInternalCache(String repoURL) {
/** Cache the estimated repository size for variants of repository URL */
private void assignSizeToInternalCache(String repoURL, long repoSize) {
repoURL = convertToCanonicalURL(repoURL);
if (repositorySizeCache.containsKey(repoURL)) {
long oldSize = repositorySizeCache.get(repoURL);
if (oldSize < repoSize) {
LOGGER.log(Level.FINE, "Replacing old repo size {0} with new size {1} for repo {2}", new Object[]{oldSize, repoSize, repoURL});
repositorySizeCache.put(repoURL, repoSize);
} else if (oldSize > repoSize) {
LOGGER.log(Level.FINE, "Ignoring new size {1} in favor of old size {0} for repo {2}", new Object[]{oldSize, repoSize, repoURL});
}
} else {
Long oldSize = repositorySizeCache.put(repoURL, repoSize);
if (oldSize == null) {
LOGGER.log(Level.FINE, "Caching repo size {0} for repo {1}", new Object[]{repoSize, repoURL});
repositorySizeCache.put(repoURL, repoSize);
} else if (oldSize < repoSize) {
LOGGER.log(Level.FINE, "Replaced old repo size {0} with new size {1} for repo {2}", new Object[]{oldSize, repoSize, repoURL});
} else if (oldSize > repoSize) {
/* Put back the larger old repo size and log a warning. This is not harmful but should be quite rare */
LOGGER.log(Level.WARNING, "Ignoring new repo size {1} in favor of old size {0} for repo {2}", new Object[]{oldSize, repoSize, repoURL});
repositorySizeCache.put(repoURL, oldSize);
}
}

Expand Down
77 changes: 77 additions & 0 deletions src/spotbugs/excludesFilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<!--
Exclusions in this section have been triaged and determined to be
false positives.
-->
<Match>
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" />
<Class name="hudson.plugins.git.GitChangeSet" />
<Method name="getUser" />
</Match>
<Match>
<Bug pattern="MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR" />
<Or>
<Class name="hudson.plugins.git.GitChangeSetList" />
<Class name="hudson.plugins.git.GitSCM" />
</Or>
</Match>
<Match>
<Bug pattern="SE_NO_SERIALVERSIONID" />
<Or>
<Class name="hudson.plugins.git.ChangelogToBranchOptions" />
<Class name="hudson.plugins.git.GitPublisher$BranchToPush" />
<Class name="hudson.plugins.git.GitPublisher$NoteToPush" />
<Class name="hudson.plugins.git.GitPublisher$TagToPush" />
<Class name="hudson.plugins.git.GitSCM$BuildChooserContextImpl" />
<Class name="hudson.plugins.git.UserMergeOptions" />
<Class name="hudson.plugins.git.UserRemoteConfig" />
<Class name="hudson.plugins.git.browser.TFS2013GitRepositoryBrowser" />
<Class name="hudson.plugins.git.extensions.impl.SparseCheckoutPath$SparseCheckoutPathToPath" />
<Class name="hudson.plugins.git.util.DefaultBuildChooser" />
<Class name="jenkins.plugins.git.AbstractGitSCMSource$SCMRevisionImpl" />
<Class name="jenkins.plugins.git.AbstractGitSCMSource$SpecificRevisionBuildChooser" />
<Class name="jenkins.plugins.git.AbstractGitSCMSource$TelescopingSCMProbe" />
<Class name="jenkins.plugins.git.AbstractGitSCMSource$TreeWalkingSCMProbe" />
<Class name="jenkins.plugins.git.GitBranchSCMHead" />
<Class name="jenkins.plugins.git.GitBranchSCMRevision" />
<Class name="jenkins.plugins.git.GitRefSCMHead" />
<Class name="jenkins.plugins.git.GitRefSCMRevision" />
<Class name="jenkins.plugins.git.GitTagSCMHead" />
<Class name="jenkins.plugins.git.GitTagSCMRevision" />
</Or>
</Match>
<Match>
<!-- Ignoring in all cases because per class exclusion seemed to be ignored -->
<Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON" />
</Match>
<Match>
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
<Class name="hudson.plugins.git.GitStatus$JenkinsAbstractProjectListener" />
<Method name="onNotifyCommit" />
</Match>
<Match>
<Bug pattern="UWF_NULL_FIELD" />
<Class name="hudson.plugins.git.SubmoduleConfig" />
<Field name="submoduleName" />
</Match>

<!--
Here lies technical debt. Exclusions in this section have not yet
been triaged. When working on this section, pick an exclusion to
triage, then:

- Add a @SuppressFBWarnings(value = "[...]", justification = "[...]")
annotation if it is a false positive. Indicate the reason why
it is a false positive, then remove the exclusion from this
section.

- If it is not a false positive, fix the bug, then remove the
exclusion from this section.
-->
<Match>
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS" />
<Class name="hudson.plugins.git.extensions.impl.PathRestriction" />
<Method name="normalize" />
</Match>
</FindBugsFilter>