Blankj/AndroidUtilCode · error · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
DebugUtils in the utildebug-no-op module is a no-op stub used in release builds to strip debug tooling at compile time. Its private constructor throws UnsupportedOperationException to prevent instantiation. All public methods (setIconId, addDebugs) are empty no-ops; the class exists only as a static API surface.
Source
Thrown at lib/utildebug-no-op/src/main/java/com/blankj/utildebug/DebugUtils.java:18
package com.blankj.utildebug;
import com.blankj.utildebug.debug.IDebug;
import java.util.List;
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/08/28
* desc : utils about debug
* </pre>
*/
public class DebugUtils {
private DebugUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
public static void setIconId(final int icon) {
}
public static void addDebugs(final List<IDebug> debugs) {
}
}
View on GitHub (pinned to 7b4caf9e54)
Solutions
- Call the (no-op) static methods: DebugUtils.setIconId(res) instead of constructing.
- Provide a Gson InstanceCreator / Jackson mixin returning a sentinel so the constructor is not invoked.
- Use Mockito.mockStatic for mocking rather than constructing DebugUtils.
- Keep the class constructor private; remember this flavor intentionally has empty bodies.
Example fix
// before DebugUtils du = new DebugUtils(); // after DebugUtils.setIconId(R.drawable.ic_debug);
Defensive patterns
Strategy: validation
Validate before calling
if (Modifier.isFinal(DebugUtils.class.getModifiers())) {
throw new IllegalStateException("DebugUtils (no-op) is static-only.");
} Prevention
- Call DebugUtils.setIconId(...)/addDebugds(...) statically.
- Remember the no-op flavor has empty bodies by design for release.
- Register InstanceCreator/mixin for JSON fields.
- Use Mockito.mockStatic for mocking.
When it happens
Trigger: Reflective instantiation via DebugUtils.class.getDeclaredConstructor().setAccessible(true).newInstance(), or transitively through Gson/Jackson deserialization, Mockito/PowerMock, Kotlin reflection, or a DI scan in a release-flavor build that resolves the no-op variant.
Common situations: Release builds swapping in the no-op artifact; serialization frameworks binding a field to DebugUtils; mock frameworks; coverage tooling; accidental construction after weakening modifiers.
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/7165150840b66816.
Report an issue: GitHub.