@@ -255,7 +255,7 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
255255 * @param obj the object to append
256256 * @return the new array (of the same component type; never {@code null})
257257 */
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 ) {
259259 return addObjectToArray (array , obj , (array != null ? array .length : 0 ));
260260 }
261261
@@ -268,17 +268,18 @@ public static <A, O extends A> A[] addObjectToArray(A @Nullable [] array, @Nulla
268268 * @return the new array (of the same component type; never {@code null})
269269 * @since 6.0
270270 */
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 ) {
272272 Class <?> componentType = Object .class ;
273273 if (array != null ) {
274274 componentType = array .getClass ().componentType ();
275275 }
276+ // Defensive code for use cases not following the declared nullability
276277 else if (obj != null ) {
277278 componentType = obj .getClass ();
278279 }
279280 int newArrayLength = (array != null ? array .length + 1 : 1 );
280281 @ SuppressWarnings ("unchecked" )
281- @ Nullable A [] newArray = (A []) Array .newInstance (componentType , newArrayLength );
282+ A [] newArray = (A []) Array .newInstance (componentType , newArrayLength );
282283 if (array != null ) {
283284 System .arraycopy (array , 0 , newArray , 0 , position );
284285 System .arraycopy (array , position , newArray , position + 1 , array .length - position );
0 commit comments