Blankj/AndroidUtilCode · warning · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
ArrayUtils is a utility class (non-final) whose private constructor throws UnsupportedOperationException. It exposes static array helpers plus the INDEX_NOT_FOUND constant; instances are intentionally forbidden.
Source
Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java:27
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/08/10
* desc : utils about array
* </pre>
*/
public class ArrayUtils {
public static final int INDEX_NOT_FOUND = -1;
private ArrayUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Returns a new array only of those given elements.
*
* @param array The array.
* @return a new array only of those given elements.
*/
@NonNull
public static <T> T[] newArray(T... array) {
return array;
}
@NonNull
public static long[] newLongArray(long... array) {
return array;
}
View on GitHub (pinned to 7b4caf9e54)
Solutions
- Use the static API, e.g. ArrayUtils.newArray(...), ArrayUtils.add(...), ArrayUtils.indexOf(...); never instantiate.
- Configure reflective frameworks to skip utility classes.
- Remove newInstance paths targeting ArrayUtils.
Example fix
// before
ArrayUtils a = reflectNew(ArrayUtils.class); // throws
// after
String[] arr = ArrayUtils.newArray("a", "b"); Defensive patterns
Strategy: validation
Validate before calling
// ArrayUtils is static-only; never instantiate.
String[] arr = ArrayUtils.newArray("a", "b"); Type guard
private static boolean isStaticUtility(Class<?> c) {
return hasOnlyStaticMethods(c);
} Prevention
- Use ArrayUtils via its static methods only.
- Configure reflective frameworks to skip utility classes.
- Remove reflective newInstance calls targeting utilities.
When it happens
Trigger: Reflective instantiation or unsafe allocation of ArrayUtils instead of calling its static methods; subclassing with a public constructor is also unusual since the base constructor throws.
Common situations: Reflection/DI/serialization frameworks that build arbitrary classes; tests that reflectively scaffold utilities.
Related errors
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14).
Data as JSON: /api/errors/d9144ddb54b2c97d.
Report an issue: GitHub.