Blankj/AndroidUtilCode · info · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
CleanUtils is a final utility class with only static cleanup helpers; its private constructor throws UnsupportedOperationException('u can't instantiate me...') to forbid construction. The throw is an intentional guard reachable only via reflection, since the class is final and the constructor is private.
Source
Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/CleanUtils.java:23
import android.os.Build;
import android.os.Environment;
import java.io.File;
import androidx.annotation.RequiresApi;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/09/27
* desc : utils about clean
* </pre>
*/
public final class CleanUtils {
private CleanUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Clean the internal cache.
* <p>directory: /data/data/package/cache</p>
*
* @return {@code true}: success<br>{@code false}: fail
*/
public static boolean cleanInternalCache() {
return UtilsBridge.deleteAllInDir(Utils.getApp().getCacheDir());
}
/**
* Clean the internal files.
* <p>directory: /data/data/package/files</p>
*
* @return {@code true}: success<br>{@code false}: fail
*/View on GitHub (pinned to 7b4caf9e54)
Solutions
- Call static methods directly (e.g., CleanUtils.cleanInternalCache()) and never instantiate.
- Exclude the constructor from coverage requirements or use the coverage helper.
- If testing the guard, assert UnsupportedOperationException is thrown rather than trying to succeed.
- Remove reflective newInstance() calls against CleanUtils.class.
Defensive patterns
Strategy: validation
Validate before calling
// Never instantiate; call static methods directly. boolean ok = CleanUtils.cleanInternalCache();
Try / catch
try {
Constructor<CleanUtils> c = CleanUtils.class.getDeclaredConstructor();
c.setAccessible(true);
c.newInstance();
} catch (UnsupportedOperationException | InvocationTargetException e) {
// expected: instantiation is forbidden by design
} Prevention
- Call CleanUtils static methods directly; never reflectively instantiate it.
- Exclude private constructors from coverage tooling that auto-instantiates.
- For guard tests, assert UnsupportedOperationException instead of trying to succeed.
When it happens
Trigger: Reflectively invoking the private constructor (setAccessible(true) + newInstance()); coverage or generic reflection tooling that instantiates every class; frameworks that auto-construct classes.
Common situations: Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests that instantiate all classes in a package; DI/serialization frameworks attempting no-arg construction.
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/9f58f45a71f5bee8.
Report an issue: GitHub.