Skip to content

Commit e9d1951

Browse files
committed
Add nullability annotation based on JavaDoc
1 parent 26a58cb commit e9d1951

36 files changed

+246
-67
lines changed

api/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
</properties>
9191

9292
<dependencies>
93+
<dependency>
94+
<groupId>jakarta.annotation</groupId>
95+
<artifactId>jakarta.annotation-api</artifactId>
96+
<version>2.1.1</version>
97+
</dependency>
9398
<dependency>
9499
<groupId>org.junit.jupiter</groupId>
95100
<artifactId>junit-jupiter-engine</artifactId>

api/src/main/java/jakarta/servlet/AsyncEvent.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package jakarta.servlet;
1919

20+
import jakarta.annotation.Nullable;
21+
2022
/**
2123
* Event that gets fired when the asynchronous operation initiated on a ServletRequest (via a call to
2224
* {@link ServletRequest#startAsync} or {@link ServletRequest#startAsync(ServletRequest, ServletResponse)}) has
@@ -29,6 +31,7 @@ public class AsyncEvent {
2931
private final AsyncContext context;
3032
private final ServletRequest request;
3133
private final ServletResponse response;
34+
@Nullable
3235
private final Throwable throwable;
3336

3437
/**
@@ -69,7 +72,7 @@ public AsyncEvent(AsyncContext context, Throwable throwable) {
6972
* @param response the ServletResponse to be delivered with this AsyncEvent
7073
* @param throwable the Throwable to be delivered with this AsyncEvent
7174
*/
72-
public AsyncEvent(AsyncContext context, ServletRequest request, ServletResponse response, Throwable throwable) {
75+
public AsyncEvent(AsyncContext context, ServletRequest request, ServletResponse response, @Nullable Throwable throwable) {
7376
this.context = context;
7477
this.request = request;
7578
this.response = response;
@@ -97,6 +100,7 @@ public AsyncContext getAsyncContext() {
97100
* @return the ServletRequest that was used to initialize this AsyncEvent, or null if this AsyncEvent was initialized
98101
* without any ServletRequest
99102
*/
103+
@Nullable
100104
public ServletRequest getSuppliedRequest() {
101105
return request;
102106
}
@@ -113,6 +117,7 @@ public ServletRequest getSuppliedRequest() {
113117
* @return the ServletResponse that was used to initialize this AsyncEvent, or null if this AsyncEvent was initialized
114118
* without any ServletResponse
115119
*/
120+
@Nullable
116121
public ServletResponse getSuppliedResponse() {
117122
return response;
118123
}
@@ -123,6 +128,7 @@ public ServletResponse getSuppliedResponse() {
123128
* @return the Throwable that was used to initialize this AsyncEvent, or null if this AsyncEvent was initialized without
124129
* any Throwable
125130
*/
131+
@Nullable
126132
public Throwable getThrowable() {
127133
return throwable;
128134
}

api/src/main/java/jakarta/servlet/FilterConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package jakarta.servlet;
2020

21+
import jakarta.annotation.Nullable;
2122
import java.util.Enumeration;
2223

2324
/**
@@ -53,6 +54,7 @@ public interface FilterConfig {
5354
* @return a <code>String</code> containing the value of the initialization parameter, or <code>null</code> if the
5455
* initialization parameter does not exist
5556
*/
57+
@Nullable
5658
String getInitParameter(String name);
5759

5860
/**

api/src/main/java/jakarta/servlet/FilterRegistration.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
package jakarta.servlet;
1919

20-
import java.util.*;
20+
import jakarta.annotation.Nullable;
21+
import java.util.Collection;
22+
import java.util.EnumSet;
2123

2224
/**
2325
* Interface through which a {@link Filter} may be further configured.
@@ -51,8 +53,9 @@ public interface FilterRegistration extends Registration {
5153
* @throws IllegalStateException if the ServletContext from which this FilterRegistration was obtained has already been
5254
* initialized
5355
*/
54-
void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
55-
String... servletNames);
56+
void addMappingForServletNames(
57+
@Nullable EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... servletNames
58+
);
5659

5760
/**
5861
* Gets the currently available servlet name mappings of the Filter represented by this <code>FilterRegistration</code>.
@@ -91,8 +94,9 @@ void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean
9194
* @throws IllegalStateException if the ServletContext from which this FilterRegistration was obtained has already been
9295
* initialized
9396
*/
94-
void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
95-
String... urlPatterns);
97+
void addMappingForUrlPatterns(
98+
@Nullable EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns
99+
);
96100

97101
/**
98102
* Gets the currently available URL pattern mappings of the Filter represented by this <code>FilterRegistration</code>.

api/src/main/java/jakarta/servlet/GenericFilter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package jakarta.servlet;
1919

20+
import jakarta.annotation.Nullable;
2021
import java.util.Enumeration;
2122
import java.util.ResourceBundle;
2223

@@ -49,6 +50,7 @@ public abstract class GenericFilter implements Filter, FilterConfig, java.io.Ser
4950
private static final String LSTRING_FILE = "jakarta.servlet.LocalStrings";
5051
private static final ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE);
5152

53+
@Nullable
5254
private transient FilterConfig config;
5355

5456
/**
@@ -79,6 +81,7 @@ public GenericFilter() {
7981
* @since Servlet 4.0
8082
*
8183
*/
84+
@Nullable
8285
@Override
8386
public String getInitParameter(String name) {
8487
FilterConfig fc = getFilterConfig();
@@ -117,13 +120,14 @@ public Enumeration<String> getInitParameterNames() {
117120

118121
/**
119122
* <p>
120-
* Returns this servlet's {@link ServletConfig} object.
123+
* Returns this servlet's {@link ServletConfig} object, or null if it has not been initialized.
121124
* </p>
122125
*
123126
* @return FilterConfig the <code>FilterConfig</code> object that initialized this filter
124127
*
125128
* @since Servlet 4.0
126129
*/
130+
@Nullable
127131
public FilterConfig getFilterConfig() {
128132
return config;
129133
}

api/src/main/java/jakarta/servlet/GenericServlet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package jakarta.servlet;
2020

21+
import jakarta.annotation.Nullable;
2122
import java.io.IOException;
2223
import java.util.Enumeration;
2324
import java.util.ResourceBundle;
@@ -50,6 +51,7 @@ public abstract class GenericServlet implements Servlet, ServletConfig, java.io.
5051
private static final String LSTRING_FILE = "jakarta.servlet.LocalStrings";
5152
private static final ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE);
5253

54+
@Nullable
5355
private transient ServletConfig config;
5456

5557
/**
@@ -83,6 +85,7 @@ public void destroy() {
8385
* @return String a <code>String</code> containing the value of the initialization parameter
8486
*
8587
*/
88+
@Nullable
8689
@Override
8790
public String getInitParameter(String name) {
8891
ServletConfig sc = getServletConfig();
@@ -117,10 +120,11 @@ public Enumeration<String> getInitParameterNames() {
117120
}
118121

119122
/**
120-
* Returns this servlet's {@link ServletConfig} object.
123+
* Returns this servlet's {@link ServletConfig} object, or <code>null</code> if it has not been initialized.
121124
*
122125
* @return ServletConfig the <code>ServletConfig</code> object that initialized this servlet
123126
*/
127+
@Nullable
124128
@Override
125129
public ServletConfig getServletConfig() {
126130
return config;

api/src/main/java/jakarta/servlet/HttpMethodConstraintElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package jakarta.servlet;
1919

20+
import jakarta.annotation.Nonnull;
2021
import jakarta.servlet.annotation.HttpMethodConstraint;
2122

2223
/**
@@ -34,7 +35,7 @@ public class HttpMethodConstraintElement extends HttpConstraintElement {
3435
* @param methodName the name of an HTTP protocol method. The name must not be null, or the empty string, and must be a
3536
* legitimate HTTP Method name as defined by RFC 7231
3637
*/
37-
public HttpMethodConstraintElement(String methodName) {
38+
public HttpMethodConstraintElement(@Nonnull String methodName) {
3839
if (methodName == null || methodName.length() == 0) {
3940
throw new IllegalArgumentException("invalid HTTP method name");
4041
}
@@ -49,7 +50,7 @@ public HttpMethodConstraintElement(String methodName) {
4950
*
5051
* @param constraint the HTTPconstraintElement value to assign to the named HTTP method
5152
*/
52-
public HttpMethodConstraintElement(String methodName, HttpConstraintElement constraint) {
53+
public HttpMethodConstraintElement(@Nonnull String methodName, HttpConstraintElement constraint) {
5354
super(constraint.getEmptyRoleSemantic(), constraint.getTransportGuarantee(), constraint.getRolesAllowed());
5455
if (methodName == null || methodName.length() == 0) {
5556
throw new IllegalArgumentException("invalid HTTP method name");

api/src/main/java/jakarta/servlet/MultipartConfigElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package jakarta.servlet;
1919

20+
import jakarta.annotation.Nullable;
2021
import jakarta.servlet.annotation.MultipartConfig;
2122

2223
/**
@@ -36,7 +37,7 @@ public class MultipartConfigElement {
3637
*
3738
* @param location defaults to "" if values is null.
3839
*/
39-
public MultipartConfigElement(String location) {
40+
public MultipartConfigElement(@Nullable String location) {
4041
if (location == null) {
4142
this.location = "";
4243
} else {
@@ -55,7 +56,7 @@ public MultipartConfigElement(String location) {
5556
* @param maxRequestSize the maximum size allowed (in bytes) for multipart/form-data requests
5657
* @param fileSizeThreshold the size threshold (in bytes) after which files will be written to disk
5758
*/
58-
public MultipartConfigElement(String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) {
59+
public MultipartConfigElement(@Nullable String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) {
5960
if (location == null) {
6061
this.location = "";
6162
} else {

api/src/main/java/jakarta/servlet/Registration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package jakarta.servlet;
1919

20+
import jakarta.annotation.Nullable;
2021
import java.util.Map;
2122
import java.util.Set;
2223

@@ -50,6 +51,7 @@ public interface Registration {
5051
* @return the fully qualified class name of the Servlet or Filter that is represented by this Registration, or null if
5152
* this Registration is preliminary
5253
*/
54+
@Nullable
5355
String getClassName();
5456

5557
/**
@@ -77,6 +79,7 @@ public interface Registration {
7779
* @return the value of the initialization parameter with the given name, or <tt>null</tt> if no initialization
7880
* parameter with the given name exists
7981
*/
82+
@Nullable
8083
String getInitParameter(String name);
8184

8285
/**

api/src/main/java/jakarta/servlet/ServletConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package jakarta.servlet;
2020

21+
import jakarta.annotation.Nullable;
2122
import java.util.Enumeration;
2223

2324
/**
@@ -51,6 +52,7 @@ public interface ServletConfig {
5152
* @return a <code>String</code> containing the value of the initialization parameter, or <code>null</code> if the
5253
* initialization parameter does not exist
5354
*/
55+
@Nullable
5456
String getInitParameter(String name);
5557

5658
/**

0 commit comments

Comments
 (0)