Skip to content

Commit

Permalink
Switch to spotbugs-annotations (#258)
Browse files Browse the repository at this point in the history
* Switch to `spotbugs-annotations`

* JSR 305 was still being used in other modules
  • Loading branch information
jglick authored Aug 16, 2021
1 parent ffde0f4 commit 4ac80fd
Show file tree
Hide file tree
Showing 30 changed files with 104 additions and 108 deletions.
5 changes: 0 additions & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/AcceptHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import javax.annotation.Nullable;
import edu.umd.cs.findbugs.annotations.Nullable;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/org/kohsuke/stapler/DispatchValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package org.kohsuke.stapler;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Validates dispatch requests. This validator is configured through {@link WebApp#setDispatchValidator(DispatchValidator)}
Expand All @@ -47,7 +47,7 @@ public interface DispatchValidator {
* @param rsp the HTTP response
* @return true if the request should be dispatched, false if not, or null if unknown or neutral
*/
@CheckForNull Boolean isDispatchAllowed(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp);
@CheckForNull Boolean isDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp);

/**
* Checks if the given request and response should be allowed to dispatch a view on an optionally present node
Expand All @@ -59,21 +59,21 @@ public interface DispatchValidator {
* @param node the node being dispatched if present
* @return true if the view should be allowed to dispatch, false if it should not, or null if unknown
*/
default @CheckForNull Boolean isDispatchAllowed(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp, @Nonnull String viewName, @CheckForNull Object node) {
default @CheckForNull Boolean isDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp, @NonNull String viewName, @CheckForNull Object node) {
return isDispatchAllowed(req, rsp);
}

/**
* Allows the given request to be dispatched. Further calls to {@link #isDispatchAllowed(StaplerRequest, StaplerResponse)}
* should return true for the same request.
*/
void allowDispatch(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp);
void allowDispatch(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp);

/**
* Throws a {@link CancelRequestHandlingException} if the given request is not
* {@linkplain #isDispatchAllowed(StaplerRequest, StaplerResponse) allowed}.
*/
default void requireDispatchAllowed(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp) throws CancelRequestHandlingException {
default void requireDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp) throws CancelRequestHandlingException {
Boolean allowed = isDispatchAllowed(req, rsp);
if (allowed == null || !allowed) {
throw new CancelRequestHandlingException();
Expand All @@ -85,12 +85,12 @@ default void requireDispatchAllowed(@Nonnull StaplerRequest req, @Nonnull Staple
*/
DispatchValidator DEFAULT = new DispatchValidator() {
@Override
public Boolean isDispatchAllowed(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp) {
public Boolean isDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp) {
return true;
}

@Override
public void allowDispatch(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp) {
public void allowDispatch(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp) {
// no-op
}
};
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/kohsuke/stapler/EvaluationTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package org.kohsuke.stapler;

import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.List;
import java.util.ArrayList;
import java.io.PrintWriter;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static void trace(StaplerRequest req, String message) {

private static volatile List<ApplicationTracer> tracers;

@Nonnull
@NonNull
private static List<ApplicationTracer> getTracers() {
synchronized (ApplicationTracer.class) {
if (tracers == null) {
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/java/org/kohsuke/stapler/Facet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.kohsuke.stapler.event.FilteredDispatchTriggerListener;
import org.kohsuke.stapler.lang.Klass;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import java.io.IOException;
Expand Down Expand Up @@ -176,7 +176,7 @@ protected boolean isBasename(String potentialPath){
* If you do want to have an extension added, you must ensure you provide the dot at the first character position,
* see JellyFacet
*/
protected @Nonnull String getExtensionSuffix() {
protected @NonNull String getExtensionSuffix() {
return "";
}

Expand All @@ -195,11 +195,11 @@ protected boolean isBasename(String potentialPath){
* @see WebApp#setFilteredDispatchTriggerListener(FilteredDispatchTriggerListener)
* @since TODO
*/
@Nonnull protected <S> Dispatcher createValidatingDispatcher(@Nonnull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@Nonnull ScriptExecutor<? super S> scriptExecutor) {
@NonNull protected <S> Dispatcher createValidatingDispatcher(@NonNull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@NonNull ScriptExecutor<? super S> scriptExecutor) {
return new Dispatcher() {
@Override
public boolean dispatch(@Nonnull RequestImpl req, @Nonnull ResponseImpl rsp, @CheckForNull Object node) throws ServletException {
public boolean dispatch(@NonNull RequestImpl req, @NonNull ResponseImpl rsp, @CheckForNull Object node) throws ServletException {
String next = req.tokens.peek();
if (next == null) {
return false;
Expand Down Expand Up @@ -261,10 +261,10 @@ public String toString() {
* Handles an index request by dispatching a script.
* @since TODO
*/
protected <S> boolean handleIndexRequest(@Nonnull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@Nonnull ScriptExecutor<? super S> scriptExecutor,
@Nonnull RequestImpl req,
@Nonnull ResponseImpl rsp,
protected <S> boolean handleIndexRequest(@NonNull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@NonNull ScriptExecutor<? super S> scriptExecutor,
@NonNull RequestImpl req,
@NonNull ResponseImpl rsp,
@CheckForNull Object node)
throws ServletException, IOException {
S script;
Expand Down Expand Up @@ -302,10 +302,10 @@ protected <S> boolean handleIndexRequest(@Nonnull AbstractTearOff<?, ? extends S
* @see WebApp#setFilteredDispatchTriggerListener(FilteredDispatchTriggerListener)
* @since TODO
*/
@CheckForNull protected <S> RequestDispatcher createRequestDispatcher(@Nonnull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@Nonnull ScriptExecutor<? super S> scriptExecutor,
@CheckForNull protected <S> RequestDispatcher createRequestDispatcher(@NonNull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@NonNull ScriptExecutor<? super S> scriptExecutor,
@CheckForNull Object it,
@Nonnull String viewName) {
@NonNull String viewName) {
return ScriptRequestDispatcher.newRequestDispatcher(scriptLoader, scriptExecutor, viewName, it);
}
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/HttpRedirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package org.kohsuke.stapler;

import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import java.io.IOException;

Expand All @@ -39,11 +39,11 @@ public final class HttpRedirect extends RuntimeException implements HttpResponse
private final int statusCode;
private final String url;

public HttpRedirect(@Nonnull String url) {
public HttpRedirect(@NonNull String url) {
this(SC_MOVED_TEMPORARILY,url);
}

public HttpRedirect(int statusCode, @Nonnull String url) {
public HttpRedirect(int statusCode, @NonNull String url) {
this.statusCode = statusCode;
if (url == null) {
throw new NullPointerException();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/HttpResponses.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package org.kohsuke.stapler;

import javax.annotation.CheckForNull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

package org.kohsuke.stapler;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -52,7 +52,7 @@ public abstract class LocaleDrivenResourceProvider {
* @return the URL to the file, if it is to be overridden, null otherwise.
*/
@CheckForNull
abstract public URL lookup(@Nonnull String path);
abstract public URL lookup(@NonNull String path);

private static List<LocaleDrivenResourceProvider> localeDrivenResourceProviders;

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/kohsuke/stapler/ResponseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void forwardToPreviousPage(StaplerRequest request) throws ServletExceptio
}

@Override
public void sendRedirect(@Nonnull String url) throws IOException {
public void sendRedirect(@NonNull String url) throws IOException {
// WebSphere doesn't apparently handle relative URLs, so
// to be safe, always resolve relative URLs to absolute URLs by ourselves.
// see http://www.nabble.com/Hudson%3A-1.262%3A-Broken-link-using-update-manager-to21067157.html
Expand All @@ -150,13 +150,13 @@ public void sendRedirect(@Nonnull String url) throws IOException {
super.sendRedirect(base);
}

public void sendRedirect2(@Nonnull String url) throws IOException {
public void sendRedirect2(@NonNull String url) throws IOException {
// Tomcat doesn't encode URL (servlet spec isn't very clear on it)
// so do the encoding by ourselves
sendRedirect(encode(url));
}

public void sendRedirect(int statusCode, @Nonnull String url) throws IOException {
public void sendRedirect(int statusCode, @NonNull String url) throws IOException {
if (statusCode==SC_MOVED_TEMPORARILY) {
sendRedirect(url); // to be safe, let the servlet container handles this default case
return;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void sendRedirect(int statusCode, @Nonnull String url) throws IOException
}

@SuppressFBWarnings(value = "HTTP_RESPONSE_SPLITTING", justification = "Already encoded and handled.")
private void setLocation(@Nonnull String url) {
private void setLocation(@NonNull String url) {
setHeader("Location",url);
}

Expand Down Expand Up @@ -396,7 +396,7 @@ private void copyAndClose(InputStream in, OutputStream out) throws IOException {
/**
* Escapes non-ASCII characters.
*/
public static @Nonnull String encode(@Nonnull String s) {
public static @NonNull String encode(@NonNull String s) {
try {
boolean escaped = false;

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/ScriptExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package org.kohsuke.stapler;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Execution strategy for handling views written in other scripting languages.
Expand All @@ -38,5 +38,5 @@ public interface ScriptExecutor<S> {
/**
* Executes the given script on the given node and request, rendering output to the given response.
*/
void execute(@Nonnull StaplerRequest req, @Nonnull StaplerResponse rsp, @Nonnull S script, @CheckForNull Object it) throws Exception;
void execute(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp, @NonNull S script, @CheckForNull Object it) throws Exception;
}
26 changes: 13 additions & 13 deletions core/src/main/java/org/kohsuke/stapler/ScriptRequestDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

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

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
Expand All @@ -47,9 +47,9 @@ class ScriptRequestDispatcher<S> implements RequestDispatcher {

private static final Logger LOGGER = Logger.getLogger(ScriptRequestDispatcher.class.getName());

@CheckForNull static <S> ScriptRequestDispatcher<S> newRequestDispatcher(@Nonnull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@Nonnull ScriptExecutor<? super S> scriptExecutor,
@Nonnull String viewName,
@CheckForNull static <S> ScriptRequestDispatcher<S> newRequestDispatcher(@NonNull AbstractTearOff<?, ? extends S, ?> scriptLoader,
@NonNull ScriptExecutor<? super S> scriptExecutor,
@NonNull String viewName,
@CheckForNull Object node) {
S script;
try {
Expand All @@ -64,16 +64,16 @@ class ScriptRequestDispatcher<S> implements RequestDispatcher {
return new ScriptRequestDispatcher<>(scriptLoader.getDefaultScriptExtension(), scriptExecutor, viewName, script, node);
}

private final @Nonnull String defaultScriptExtension;
private final @Nonnull ScriptExecutor<? super S> scriptExecutor;
private final @Nonnull String viewName;
private final @Nonnull S script;
private final @NonNull String defaultScriptExtension;
private final @NonNull ScriptExecutor<? super S> scriptExecutor;
private final @NonNull String viewName;
private final @NonNull S script;
private final @CheckForNull Object node;

private ScriptRequestDispatcher(@Nonnull String defaultScriptExtension,
@Nonnull ScriptExecutor<? super S> scriptExecutor,
@Nonnull String viewName,
@Nonnull S script,
private ScriptRequestDispatcher(@NonNull String defaultScriptExtension,
@NonNull ScriptExecutor<? super S> scriptExecutor,
@NonNull String viewName,
@NonNull S script,
@CheckForNull Object node) {
this.defaultScriptExtension = defaultScriptExtension;
this.scriptExecutor = scriptExecutor;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/StaplerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.kohsuke.stapler.export.Model;
import org.kohsuke.stapler.export.NamedPathPruner;

import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -74,12 +74,12 @@ public interface StaplerResponse extends HttpServletResponse {
* Works like {@link #sendRedirect(String)} except that this method
* escapes the URL.
*/
void sendRedirect2(@Nonnull String url) throws IOException;
void sendRedirect2(@NonNull String url) throws IOException;

/**
* Works like {@link #sendRedirect2(String)} but allows the caller to specify the HTTP status code.
*/
void sendRedirect(int statusCore, @Nonnull String url) throws IOException;
void sendRedirect(int statusCore, @NonNull String url) throws IOException;

/**
* Serves a static resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.kohsuke.stapler.export.ExportConfig;
import org.kohsuke.stapler.export.Flavor;

import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
Expand Down Expand Up @@ -35,7 +35,7 @@ public StaplerResponseWrapper(StaplerResponse wrapped) {
/**
* Returns the wrapped instance
*/
@Nonnull
@NonNull
public StaplerResponse getWrapped() {
return wrapped;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.jvnet.tiger_types.Types;

import javax.annotation.Nullable;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.lang.reflect.Type;

/**
Expand Down
Loading

0 comments on commit 4ac80fd

Please sign in to comment.