Skip to content

Commit 7b7bea8

Browse files
authored
Replace JSR-305 annotations with spotbugs annotations (#49)
Annotations for Nonnull, CheckForNull, and several others were proposed for Java as part of dormant Java specification request JSR-305. The proposal never became a part of standard Java. Jenkins plugins should switch from using JSR-305 annotations to use Spotbugs annotations that provide the same semantics. The [mailing list discussion](https://groups.google.com/g/jenkinsci-dev/c/uE1wwtVi1W0/m/gLxdEJmlBQAJ) from James Nord describes the affected annotations and why they should be replaced with annotations that are actively maintained. The ["Improve a plugin" tutorial](https://www.jenkins.io/doc/developer/tutorial-improve/replace-jsr-305-annotations/) provides instructions to perform this change. An [OpenRewrite recipe](https://docs.openrewrite.org/recipes/jenkins/javaxannotationstospotbugs) is also available and is even better than the tutorial. Confirmed that automated tests pass on Linux with Java 21.
1 parent 23ec041 commit 7b7bea8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/main/java/hudson/plugins/deploy/ContainerAdapterDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.IOException;
44
import java.net.URL;
55

6-
import javax.annotation.CheckForNull;
6+
import edu.umd.cs.findbugs.annotations.CheckForNull;
77

88
import org.apache.commons.lang.StringUtils;
99
import org.kohsuke.accmod.Restricted;

src/main/java/hudson/plugins/deploy/DeployPublisher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.logging.Level;
1010
import java.util.logging.Logger;
1111

12-
import javax.annotation.Nonnull;
12+
import edu.umd.cs.findbugs.annotations.NonNull;
1313

1414
import org.jenkinsci.Symbol;
1515
import org.kohsuke.accmod.Restricted;
@@ -86,7 +86,7 @@ public void setContextPath (String contextPath) {
8686
}
8787

8888
@Override
89-
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
89+
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull Launcher launcher, @NonNull TaskListener listener) throws InterruptedException, IOException {
9090
Result result = run.getResult();
9191
if (onFailure || result == null || Result.SUCCESS.equals(result)) {
9292
if (!workspace.exists()) {

src/main/java/hudson/plugins/deploy/PasswordProtectedAdapterCargo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.kohsuke.accmod.restrictions.DoNotUse;
2020
import org.kohsuke.accmod.restrictions.NoExternalUse;
2121

22-
import javax.annotation.CheckForNull;
22+
import edu.umd.cs.findbugs.annotations.CheckForNull;
2323
import java.io.IOException;
2424
import java.util.ArrayList;
2525
import java.util.List;

0 commit comments

Comments
 (0)