Skip to content

Commit

Permalink
Replace Nullable with CheckForNull.
Browse files Browse the repository at this point in the history
`CheckForNull` is now supported by NullAway as well:
See uber/NullAway#397
  • Loading branch information
uhafner committed Aug 24, 2020
1 parent 5328024 commit ef0bff8
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 70 deletions.
12 changes: 9 additions & 3 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<module.name>${project.groupId}.warnings.ng</module.name>
<jenkins.version>${jenkins.baseline}.6</jenkins.version>


<codingstyle.config.version>1.4.0</codingstyle.config.version>
<analysis-model-api.version>8.2.1</analysis-model-api.version>
<analysis-model-tests.version>${analysis-model-api.version}</analysis-model-tests.version>
<forensics-api-plugin.version>0.7.0</forensics-api-plugin.version>
Expand Down Expand Up @@ -625,10 +626,15 @@
<code>java.missing.*</code>
<justification>Dependencies are not being checked, so they are reported as missing</justification>
</item>
<item>
<code>java.annotation.removed</code>
<annotation>@edu.umd.cs.findbugs.annotations.Nullable</annotation>
<justification>Annotation should be save to change.</justification>
</item>
<item>
<code>java.annotation.added</code>
<annotationType>org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted</annotationType>
<justification>Annotation should be save to add.</justification>
<annotation>@edu.umd.cs.findbugs.annotations.CheckForNull</annotation>
<justification>Annotation should be save to change.</justification>
</item>
</revapi.ignore>
</analysisConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.stream.Collectors;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import hudson.model.Action;
Expand All @@ -28,19 +28,19 @@
public class AggregationAction implements RunAction2, LastBuildAction {
private transient Run<?, ?> owner;

@Nullable
@CheckForNull
@Override
public String getIconFileName() {
return null; // No UI representation up to now
}

@Nullable
@CheckForNull
@Override
public String getDisplayName() {
return Messages.Aggregation_Name();
}

@Nullable
@CheckForNull
@Override
public String getUrlName() {
return "warnings-ng";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.echarts.BuildResult;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import hudson.model.Result;
import hudson.model.Run;
Expand Down Expand Up @@ -151,7 +151,7 @@ private Optional<ResultAction> getPreviousAction() {
return Optional.empty();
}

private static Optional<Run<?, ?>> getRunWithResult(final @Nullable Run<?, ?> start,
private static Optional<Run<?, ?>> getRunWithResult(final @CheckForNull Run<?, ?> start,
final ResultSelector selector,
final QualityGateEvaluationMode qualityGateEvaluationMode,
final JobResultEvaluationMode jobResultEvaluationMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.echarts.Build;
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
Expand Down Expand Up @@ -75,27 +75,27 @@ public class AnalysisResult implements Serializable, StaticAnalysisRun {
/**
* All outstanding issues: i.e. all issues, that are part of the current and reference report.
*/
@Nullable
@CheckForNull
private transient WeakReference<Report> outstandingIssuesReference;
/**
* All new issues: i.e. all issues, that are part of the current report but have not been shown up in the reference
* report.
*/
@Nullable
@CheckForNull
private transient WeakReference<Report> newIssuesReference;
/**
* All fixed issues: i.e. all issues, that are part of the reference report but are not present in the current
* report anymore.
*/
@Nullable
@CheckForNull
private transient WeakReference<Report> fixedIssuesReference;

/** All SCM blames. Provides a mapping of file names to SCM commit information like author, email or commit ID. */
@Nullable
@CheckForNull
private transient WeakReference<Blames> blamesReference;

/** Statistics for all files. Provides a mapping of file names to SCM statistics like #authors, #commits, etc. */
@Nullable
@CheckForNull
private transient WeakReference<RepositoryStatistics> repositoryStatistics;

/** Determines since which build we have zero warnings. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import edu.hm.hafner.echarts.ChartModelConfiguration;
import edu.hm.hafner.echarts.JacksonFacade;
import edu.hm.hafner.echarts.LinesChartModel;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down Expand Up @@ -135,7 +135,7 @@ public History createBuildHistory() {
* @return the icon URL for the side-panel in the job screen
*/
@Override
@Nullable
@CheckForNull
public String getIconFileName() {
return createBuildHistory().getBaselineResult()
.map(result -> Jenkins.RESOURCE_PATH + labelProvider.getSmallIconUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
Expand Down Expand Up @@ -57,7 +57,7 @@ public StaticAnalysisLabelProvider create(final String id) {
* @return The label provider of the selected static analysis tool. If the tool is not found then a default label
* provider is returned.
*/
public StaticAnalysisLabelProvider create(final String id, @Nullable final String name) {
public StaticAnalysisLabelProvider create(final String id, @CheckForNull final String name) {
DescriptorExtensionList<Tool, ToolDescriptor> extensions = jenkins.getDescriptorsFor(Tool.class);
for (ToolDescriptor descriptor : extensions) {
if (descriptor.getId().equals(id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.util.Ensure;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -62,7 +62,7 @@ public void setPattern(final String pattern) {
this.pattern = pattern;
}

@Nullable
@CheckForNull
public String getPattern() {
return pattern;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public void setReportEncoding(final String reportEncoding) {
this.reportEncoding = reportEncoding;
}

@Nullable
@CheckForNull
public String getReportEncoding() {
return reportEncoding;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.jenkins.plugins.analysis.core.model;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import hudson.model.Action;

Expand Down Expand Up @@ -30,19 +30,19 @@ public String getId() {
return id;
}

@Nullable
@CheckForNull
@Override
public String getIconFileName() {
return null;
}

@Nullable
@CheckForNull
@Override
public String getDisplayName() {
return null;
}

@Nullable
@CheckForNull
@Override
public String getUrlName() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import org.apache.commons.lang3.StringUtils;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import org.kohsuke.stapler.StaplerProxy;
Expand Down Expand Up @@ -188,7 +188,7 @@ public String getAbsoluteUrl() {
}

@Override
@Nullable
@CheckForNull
public HealthReport getBuildHealth() {
return new HealthReportBuilder().computeHealth(healthDescriptor, getLabelProvider(),
getResult().getSizePerSeverity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import j2html.tags.ContainerTag;
import j2html.tags.DomContent;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class StaticAnalysisLabelProvider implements DescriptionProvider {
static final String INFO_ICON = "info-circle";

private final String id;
@Nullable
@CheckForNull
private String name;
private final JenkinsFacade jenkins;

Expand All @@ -66,12 +66,12 @@ public StaticAnalysisLabelProvider(final String id) {
* @param name
* the name of the static analysis tool
*/
public StaticAnalysisLabelProvider(final String id, @Nullable final String name) {
public StaticAnalysisLabelProvider(final String id, @CheckForNull final String name) {
this(id, name, new JenkinsFacade());
}

@VisibleForTesting
StaticAnalysisLabelProvider(final String id, @Nullable final String name, final JenkinsFacade jenkins) {
StaticAnalysisLabelProvider(final String id, @CheckForNull final String name, final JenkinsFacade jenkins) {
this.id = id;
this.name = SANITIZER.render(name);
this.jenkins = jenkins;
Expand Down Expand Up @@ -153,7 +153,7 @@ public String getName() {
*
* @return the name
*/
public StaticAnalysisLabelProvider setName(@Nullable final String name) {
public StaticAnalysisLabelProvider setName(@CheckForNull final String name) {
if (StringUtils.isNotBlank(name)) { // don't overwrite with empty
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand Down Expand Up @@ -62,7 +62,7 @@ public QualityGateStatus getQualityGateStatus() {
}

@Exported
@Nullable
@CheckForNull
public Run<?, ?> getReferenceBuild() {
return result.getReferenceBuild().orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.google.errorprone.annotations.FormatMethod;

import edu.hm.hafner.analysis.Report;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;

Expand Down Expand Up @@ -51,7 +51,7 @@ public AnnotatedReport(final String id) {
* @param report
* report with issues
*/
public AnnotatedReport(@Nullable final String id, final Report report) {
public AnnotatedReport(@CheckForNull final String id, final Report report) {
this(id, report, new Blames(), new RepositoryStatistics());
}

Expand All @@ -67,7 +67,7 @@ public AnnotatedReport(@Nullable final String id, final Report report) {
* @param statistics
* repository statistics for affected files
*/
public AnnotatedReport(@Nullable final String id, final Report report, final Blames blames,
public AnnotatedReport(@CheckForNull final String id, final Report report, final Blames blames,
final RepositoryStatistics statistics) {
this(id);

Expand All @@ -82,7 +82,7 @@ public AnnotatedReport(@Nullable final String id, final Report report, final Bla
* @param reports
* the reports to aggregate
*/
public AnnotatedReport(@Nullable final String id, final List<AnnotatedReport> reports) {
public AnnotatedReport(@CheckForNull final String id, final List<AnnotatedReport> reports) {
this(id);

addAllReports(reports);
Expand All @@ -96,7 +96,7 @@ public AnnotatedReport(@Nullable final String id, final List<AnnotatedReport> re
* @param reports
* the reports to aggregate
*/
public AnnotatedReport(@Nullable final String id, final Iterable<AnnotatedReport> reports) {
public AnnotatedReport(@CheckForNull final String id, final Iterable<AnnotatedReport> reports) {
this(id);

addAllReports(reports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Severity;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -227,7 +227,7 @@ public String getName() {
* @see #getTools
* @deprecated this method is only intended to be called by the UI
*/
@Nullable
@CheckForNull
@Deprecated
public List<ToolProxy> getToolProxies() {
return analysisTools.stream().map(ToolProxy::new).collect(Collectors.toList());
Expand Down Expand Up @@ -284,7 +284,7 @@ public List<Tool> getTools() {
return new ArrayList<>(analysisTools);
}

@Nullable
@CheckForNull
public String getSourceCodeEncoding() {
return sourceCodeEncoding;
}
Expand Down Expand Up @@ -533,7 +533,7 @@ public void setUnhealthy(final int unhealthy) {
this.unhealthy = unhealthy;
}

@Nullable
@CheckForNull
public String getMinimumSeverity() {
return minimumSeverity.getName();
}
Expand Down
Loading

0 comments on commit ef0bff8

Please sign in to comment.