2424import jakarta .servlet .WriteListener ;
2525import jakarta .servlet .http .HttpServletResponse ;
2626import jakarta .servlet .http .HttpServletResponseWrapper ;
27+ import org .jspecify .annotations .Nullable ;
2728
2829/**
2930 * Base class for response wrappers which encapsulate the logic for handling an event when
@@ -57,37 +58,37 @@ public OnCommittedResponseWrapper(HttpServletResponse response) {
5758 }
5859
5960 @ Override
60- public void addHeader (String name , String value ) {
61+ public void addHeader (@ Nullable String name , @ Nullable String value ) {
6162 checkContentLengthHeader (name , value );
6263 super .addHeader (name , value );
6364 }
6465
6566 @ Override
66- public void addIntHeader (String name , int value ) {
67+ public void addIntHeader (@ Nullable String name , int value ) {
6768 checkContentLengthHeader (name , value );
6869 super .addIntHeader (name , value );
6970 }
7071
7172 @ Override
72- public void setHeader (String name , String value ) {
73+ public void setHeader (@ Nullable String name , @ Nullable String value ) {
7374 checkContentLengthHeader (name , value );
7475 super .setHeader (name , value );
7576 }
7677
7778 @ Override
78- public void setIntHeader (String name , int value ) {
79+ public void setIntHeader (@ Nullable String name , int value ) {
7980 checkContentLengthHeader (name , value );
8081 super .setIntHeader (name , value );
8182 }
8283
83- private void checkContentLengthHeader (String name , int value ) {
84+ private void checkContentLengthHeader (@ Nullable String name , int value ) {
8485 if ("Content-Length" .equalsIgnoreCase (name )) {
8586 setContentLength (value );
8687 }
8788 }
8889
89- private void checkContentLengthHeader (String name , String value ) {
90- if ("Content-Length" .equalsIgnoreCase (name )) {
90+ private void checkContentLengthHeader (@ Nullable String name , @ Nullable String value ) {
91+ if (value != null && "Content-Length" .equalsIgnoreCase (name )) {
9192 setContentLength (Long .parseLong (value ));
9293 }
9394 }
@@ -149,7 +150,7 @@ public final void sendError(int sc) throws IOException {
149150 * before calling the superclass <code>sendError()</code>
150151 */
151152 @ Override
152- public final void sendError (int sc , String msg ) throws IOException {
153+ public final void sendError (int sc , @ Nullable String msg ) throws IOException {
153154 doOnResponseCommitted ();
154155 super .sendError (sc , msg );
155156 }
@@ -159,7 +160,7 @@ public final void sendError(int sc, String msg) throws IOException {
159160 * before calling the superclass <code>sendRedirect()</code>
160161 */
161162 @ Override
162- public final void sendRedirect (String location ) throws IOException {
163+ public final void sendRedirect (@ Nullable String location ) throws IOException {
163164 doOnResponseCommitted ();
164165 super .sendRedirect (location );
165166 }
@@ -206,7 +207,7 @@ private void trackContentLength(char content) {
206207 }
207208 }
208209
209- private void trackContentLength (Object content ) {
210+ private void trackContentLength (@ Nullable Object content ) {
210211 if (!this .disableOnCommitted ) {
211212 trackContentLength (String .valueOf (content ));
212213 }
@@ -248,7 +249,7 @@ private void trackContentLengthLn() {
248249 }
249250 }
250251
251- private void trackContentLength (String content ) {
252+ private void trackContentLength (@ Nullable String content ) {
252253 if (!this .disableOnCommitted ) {
253254 int contentLength = (content != null ) ? content .length () : 4 ;
254255 checkContentLength (contentLength );
@@ -355,7 +356,7 @@ public void write(String s, int off, int len) {
355356 }
356357
357358 @ Override
358- public void write (String s ) {
359+ public void write (@ Nullable String s ) {
359360 trackContentLength (s );
360361 this .delegate .write (s );
361362 }
@@ -403,13 +404,13 @@ public void print(char[] s) {
403404 }
404405
405406 @ Override
406- public void print (String s ) {
407+ public void print (@ Nullable String s ) {
407408 trackContentLength (s );
408409 this .delegate .print (s );
409410 }
410411
411412 @ Override
412- public void print (Object obj ) {
413+ public void print (@ Nullable Object obj ) {
413414 trackContentLength (obj );
414415 this .delegate .print (obj );
415416 }
@@ -470,14 +471,14 @@ public void println(char[] x) {
470471 }
471472
472473 @ Override
473- public void println (String x ) {
474+ public void println (@ Nullable String x ) {
474475 trackContentLength (x );
475476 trackContentLengthLn ();
476477 this .delegate .println (x );
477478 }
478479
479480 @ Override
480- public void println (Object x ) {
481+ public void println (@ Nullable Object x ) {
481482 trackContentLength (x );
482483 trackContentLengthLn ();
483484 this .delegate .println (x );
@@ -504,13 +505,13 @@ public PrintWriter format(Locale l, String format, Object... args) {
504505 }
505506
506507 @ Override
507- public PrintWriter append (CharSequence csq ) {
508- checkContentLength (csq .length ());
508+ public PrintWriter append (@ Nullable CharSequence csq ) {
509+ checkContentLength (( csq != null ) ? csq .length () : 4 );
509510 return this .delegate .append (csq );
510511 }
511512
512513 @ Override
513- public PrintWriter append (CharSequence csq , int start , int end ) {
514+ public PrintWriter append (@ Nullable CharSequence csq , int start , int end ) {
514515 checkContentLength (end - start );
515516 return this .delegate .append (csq , start , end );
516517 }
@@ -595,7 +596,7 @@ public void print(long l) throws IOException {
595596 }
596597
597598 @ Override
598- public void print (String s ) throws IOException {
599+ public void print (@ Nullable String s ) throws IOException {
599600 trackContentLength (s );
600601 this .delegate .print (s );
601602 }
@@ -649,7 +650,7 @@ public void println(long l) throws IOException {
649650 }
650651
651652 @ Override
652- public void println (String s ) throws IOException {
653+ public void println (@ Nullable String s ) throws IOException {
653654 trackContentLength (s );
654655 trackContentLengthLn ();
655656 this .delegate .println (s );
0 commit comments