Blankj/AndroidUtilCode · warning · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
DangerousUtils is a utility class whose private constructor throws UnsupportedOperationException to block instantiation. All functionality is exposed as static methods; the class is not meant to hold instance state.
Source
Thrown at lib/subutil/src/main/java/com/blankj/subutil/util/DangerousUtils.java:37
import java.util.List;
import androidx.annotation.RequiresPermission;
import static android.Manifest.permission.MODIFY_PHONE_STATE;
import static android.Manifest.permission.SEND_SMS;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2019/06/29
* desc :
* </pre>
*/
public class DangerousUtils {
private DangerousUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
///////////////////////////////////////////////////////////////////////////
// AppUtils
///////////////////////////////////////////////////////////////////////////
/**
* Install the app silently.
* <p>Without root permission must hold
* {@code android:sharedUserId="android.uid.shell"} and
* {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
*
* @param filePath The path of file.
* @return {@code true}: success<br>{@code false}: fail
*/
public static boolean installAppSilent(final String filePath) {
return installAppSilent(getFileByPath(filePath), null);
}View on GitHub (pinned to 7b4caf9e54)
Solutions
- Use the static methods directly, e.g. DangerousUtils.silentInstall(...); never hold an instance.
- Configure reflective frameworks to skip final utility classes.
- Remove reflection that constructs DangerousUtils.
Example fix
// before DangerousUtils d = reflectiveNew(DangerousUtils.class); // throws // after DangerousUtils.installAppSilent(filePath, listener);
Defensive patterns
Strategy: validation
Validate before calling
// DangerousUtils is static-only; never instantiate. DangerousUtils.installAppSilent(path, listener);
Type guard
private static boolean isStaticUtility(Class<?> c) {
return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);
} Prevention
- Use DangerousUtils via its static methods only.
- Configure DI/serialization frameworks to skip utility classes.
- Remove reflective newInstance calls targeting utilities.
When it happens
Trigger: Reflective instantiation (Constructor.newInstance) or unsafe object creation targeting DangerousUtils.
Common situations: DI/serialization frameworks or code generators that instantiate arbitrary classes; reflective test scaffolding that builds utility classes.
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/51a66251eec14e79.
Report an issue: GitHub.