21
21
import java .io .Serializable ;
22
22
import java .lang .reflect .Method ;
23
23
import java .lang .reflect .Type ;
24
+ import java .nio .charset .StandardCharsets ;
24
25
import java .util .ArrayList ;
25
26
import java .util .Arrays ;
26
27
import java .util .Collections ;
@@ -130,7 +131,7 @@ public void setup() throws Exception {
130
131
@ Test
131
132
public void resolveArgumentParameterizedType () throws Exception {
132
133
String content = "[{\" name\" : \" Jad\" }, {\" name\" : \" Robert\" }]" ;
133
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
134
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
134
135
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
135
136
136
137
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -150,7 +151,7 @@ public void resolveArgumentParameterizedType() throws Exception {
150
151
public void resolveArgumentRawTypeFromParameterizedType () throws Exception {
151
152
String content = "fruit=apple&vegetable=kale" ;
152
153
this .servletRequest .setMethod ("GET" );
153
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
154
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
154
155
this .servletRequest .setContentType (MediaType .APPLICATION_FORM_URLENCODED_VALUE );
155
156
156
157
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -169,7 +170,7 @@ public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
169
170
@ Test
170
171
public void resolveArgumentClassJson () throws Exception {
171
172
String content = "{\" name\" : \" Jad\" }" ;
172
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
173
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
173
174
this .servletRequest .setContentType ("application/json" );
174
175
175
176
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -186,7 +187,7 @@ public void resolveArgumentClassJson() throws Exception {
186
187
@ Test
187
188
public void resolveArgumentClassString () throws Exception {
188
189
String content = "foobarbaz" ;
189
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
190
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
190
191
this .servletRequest .setContentType ("application/json" );
191
192
192
193
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -201,7 +202,7 @@ public void resolveArgumentClassString() throws Exception {
201
202
}
202
203
203
204
@ Test // SPR-9942
204
- public void resolveArgumentRequiredNoContent () throws Exception {
205
+ public void resolveArgumentRequiredNoContent () {
205
206
this .servletRequest .setContent (new byte [0 ]);
206
207
this .servletRequest .setContentType ("text/plain" );
207
208
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -230,7 +231,7 @@ public void resolveArgumentTypeVariable() throws Exception {
230
231
MethodParameter methodParam = handlerMethod .getMethodParameters ()[0 ];
231
232
232
233
String content = "{\" name\" : \" Jad\" }" ;
233
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
234
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
234
235
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
235
236
236
237
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -250,7 +251,7 @@ public void resolveParameterizedWithTypeVariableArgument() throws Exception {
250
251
MethodParameter methodParam = handlerMethod .getMethodParameters ()[0 ];
251
252
252
253
String content = "[{\" name\" : \" Jad\" }, {\" name\" : \" Robert\" }]" ;
253
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
254
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
254
255
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
255
256
256
257
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -273,7 +274,7 @@ public void resolveArgumentTypeVariableWithNonGenericConverter() throws Exceptio
273
274
MethodParameter methodParam = handlerMethod .getMethodParameters ()[0 ];
274
275
275
276
String content = "{\" name\" : \" Jad\" }" ;
276
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
277
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
277
278
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
278
279
279
280
List <HttpMessageConverter <?>> converters = new ArrayList <>();
@@ -609,7 +610,7 @@ public void jacksonJsonViewWithResponseEntityAndXmlMessageConverter() throws Exc
609
610
@ Test // SPR-12501
610
611
public void resolveArgumentWithJacksonJsonView () throws Exception {
611
612
String content = "{\" withView1\" : \" with\" , \" withView2\" : \" with\" , \" withoutView\" : \" without\" }" ;
612
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
613
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
613
614
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
614
615
615
616
Method method = JacksonController .class .getMethod ("handleRequestBody" , JacksonViewBean .class );
@@ -634,7 +635,7 @@ public void resolveArgumentWithJacksonJsonView() throws Exception {
634
635
@ Test // SPR-12501
635
636
public void resolveHttpEntityArgumentWithJacksonJsonView () throws Exception {
636
637
String content = "{\" withView1\" : \" with\" , \" withView2\" : \" with\" , \" withoutView\" : \" without\" }" ;
637
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
638
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
638
639
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
639
640
640
641
Method method = JacksonController .class .getMethod ("handleHttpEntity" , HttpEntity .class );
@@ -664,7 +665,7 @@ public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Ex
664
665
"<withView1>with</withView1>" +
665
666
"<withView2>with</withView2>" +
666
667
"<withoutView>without</withoutView></root>" ;
667
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
668
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
668
669
this .servletRequest .setContentType (MediaType .APPLICATION_XML_VALUE );
669
670
670
671
Method method = JacksonController .class .getMethod ("handleRequestBody" , JacksonViewBean .class );
@@ -692,7 +693,7 @@ public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter()
692
693
"<withView1>with</withView1>" +
693
694
"<withView2>with</withView2>" +
694
695
"<withoutView>without</withoutView></root>" ;
695
- this .servletRequest .setContent (content .getBytes ("UTF-8" ));
696
+ this .servletRequest .setContent (content .getBytes (StandardCharsets . UTF_8 ));
696
697
this .servletRequest .setContentType (MediaType .APPLICATION_XML_VALUE );
697
698
698
699
Method method = JacksonController .class .getMethod ("handleHttpEntity" , HttpEntity .class );
@@ -774,7 +775,7 @@ public void jacksonSubTypeList() throws Exception {
774
775
775
776
@ Test // SPR-14520
776
777
public void resolveArgumentTypeVariableWithGenericInterface () throws Exception {
777
- this .servletRequest .setContent ("\" foo\" " .getBytes ("UTF-8" ));
778
+ this .servletRequest .setContent ("\" foo\" " .getBytes (StandardCharsets . UTF_8 ));
778
779
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
779
780
780
781
Method method = MyControllerImplementingInterface .class .getMethod ("handle" , Object .class );
@@ -794,7 +795,7 @@ public void resolveArgumentTypeVariableWithGenericInterface() throws Exception {
794
795
795
796
@ Test // gh-24127
796
797
public void resolveArgumentTypeVariableWithGenericInterfaceAndSubclass () throws Exception {
797
- this .servletRequest .setContent ("\" foo\" " .getBytes ("UTF-8" ));
798
+ this .servletRequest .setContent ("\" foo\" " .getBytes (StandardCharsets . UTF_8 ));
798
799
this .servletRequest .setContentType (MediaType .APPLICATION_JSON_VALUE );
799
800
800
801
Method method = SubControllerImplementingInterface .class .getMethod ("handle" , Object .class );
@@ -836,6 +837,7 @@ private void assertContentDisposition(RequestResponseBodyMethodProcessor process
836
837
}
837
838
838
839
840
+ @ SuppressWarnings ("ConstantConditions" )
839
841
String handle (
840
842
@ RequestBody List <SimpleBean > list ,
841
843
@ RequestBody SimpleBean simpleBean ,
@@ -845,19 +847,23 @@ String handle(
845
847
return null ;
846
848
}
847
849
850
+ @ SuppressWarnings ("ConstantConditions" )
848
851
Resource getImage () {
849
852
return null ;
850
853
}
851
854
855
+ @ SuppressWarnings ("ConstantConditions" )
852
856
ProblemDetail handleAndReturnProblemDetail () {
853
857
return null ;
854
858
}
855
859
860
+ @ SuppressWarnings ("ConstantConditions" )
856
861
@ RequestMapping
857
862
OutputStream handleAndReturnOutputStream () {
858
863
return null ;
859
864
}
860
865
866
+ @ SuppressWarnings ("ConstantConditions" )
861
867
SimpleBean getSimpleBean () {
862
868
return null ;
863
869
}
@@ -895,7 +901,7 @@ private static class MySimpleParameterizedControllerWithList extends MyParameter
895
901
}
896
902
897
903
898
- @ SuppressWarnings ({ "serial" } )
904
+ @ SuppressWarnings ("NotNullFieldNotInitialized" )
899
905
private static class SimpleBean implements Identifiable {
900
906
901
907
private Long id ;
@@ -922,7 +928,7 @@ public void setName(String name) {
922
928
}
923
929
924
930
925
- private final class ValidatingBinderFactory implements WebDataBinderFactory {
931
+ private static final class ValidatingBinderFactory implements WebDataBinderFactory {
926
932
927
933
@ Override
928
934
public WebDataBinder createBinder (NativeWebRequest request , @ Nullable Object target , String objectName ) {
@@ -943,6 +949,7 @@ public String handle() {
943
949
return "hello" ;
944
950
}
945
951
952
+ @ SuppressWarnings ("ConstantConditions" )
946
953
@ RequestMapping
947
954
public CharSequence handleWithCharSequence () {
948
955
return null ;
@@ -965,6 +972,7 @@ private interface MyJacksonView1 {}
965
972
private interface MyJacksonView2 {}
966
973
967
974
975
+ @ SuppressWarnings ("NotNullFieldNotInitialized" )
968
976
private static class JacksonViewBean {
969
977
970
978
@ JsonView (MyJacksonView1 .class )
@@ -983,6 +991,7 @@ public void setWithView1(String withView1) {
983
991
this .withView1 = withView1 ;
984
992
}
985
993
994
+ @ Nullable
986
995
public String getWithView2 () {
987
996
return withView2 ;
988
997
}
@@ -991,6 +1000,7 @@ public void setWithView2(String withView2) {
991
1000
this .withView2 = withView2 ;
992
1001
}
993
1002
1003
+ @ Nullable
994
1004
public String getWithoutView () {
995
1005
return withoutView ;
996
1006
}
@@ -1001,7 +1011,8 @@ public void setWithoutView(String withoutView) {
1001
1011
}
1002
1012
1003
1013
1004
- @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , include = JsonTypeInfo .As .PROPERTY , property = "type" )
1014
+ @ SuppressWarnings ("NotNullFieldNotInitialized" )
1015
+ @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , property = "type" )
1005
1016
public static class ParentClass {
1006
1017
1007
1018
private String parentProperty ;
@@ -1092,6 +1103,7 @@ public JacksonViewBean handleRequestBody(@JsonView(MyJacksonView1.class) @Reques
1092
1103
return bean ;
1093
1104
}
1094
1105
1106
+ @ SuppressWarnings ("ConstantConditions" )
1095
1107
@ RequestMapping
1096
1108
@ ResponseBody
1097
1109
public JacksonViewBean handleHttpEntity (@ JsonView (MyJacksonView1 .class ) HttpEntity <JacksonViewBean > entity ) {
0 commit comments