@@ -255,7 +255,7 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
255
255
* @param obj the object to append
256
256
* @return the new array (of the same component type; never {@code null})
257
257
*/
258
- public static <A , O extends A > A [] addObjectToArray (A @ Nullable [] array , @ Nullable O obj ) {
258
+ public static <A , O extends A > A [] addObjectToArray (A @ Nullable [] array , O obj ) {
259
259
return addObjectToArray (array , obj , (array != null ? array .length : 0 ));
260
260
}
261
261
@@ -268,17 +268,18 @@ public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, @Nulla
268
268
* @return the new array (of the same component type; never {@code null})
269
269
* @since 6.0
270
270
*/
271
- public static <A , O extends A > @ Nullable A [] addObjectToArray (A @ Nullable [] array , @ Nullable O obj , int position ) {
271
+ public static <A , O extends A > A [] addObjectToArray (A @ Nullable [] array , O obj , int position ) {
272
272
Class <?> componentType = Object .class ;
273
273
if (array != null ) {
274
274
componentType = array .getClass ().componentType ();
275
275
}
276
+ // Defensive code for use cases not following the declared nullability
276
277
else if (obj != null ) {
277
278
componentType = obj .getClass ();
278
279
}
279
280
int newArrayLength = (array != null ? array .length + 1 : 1 );
280
281
@ SuppressWarnings ("unchecked" )
281
- @ Nullable A [] newArray = (A []) Array .newInstance (componentType , newArrayLength );
282
+ A [] newArray = (A []) Array .newInstance (componentType , newArrayLength );
282
283
if (array != null ) {
283
284
System .arraycopy (array , 0 , newArray , 0 , position );
284
285
System .arraycopy (array , position , newArray , position + 1 , array .length - position );
0 commit comments