Blankj/AndroidUtilCode · info · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
CloseUtils is a final utility class with static IO-close 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/CloseUtils.java:17
package com.blankj.utilcode.util;
import java.io.Closeable;
import java.io.IOException;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/09
* desc : utils about close
* </pre>
*/
public final class CloseUtils {
private CloseUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Close the io stream.
*
* @param closeables The closeables.
*/
public static void closeIO(final Closeable... closeables) {
if (closeables == null) return;
for (Closeable closeable : closeables) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}View on GitHub (pinned to 7b4caf9e54)
Solutions
- Call static methods directly (e.g., CloseUtils.closeIO(stream)) and never instantiate.
- Exclude the constructor from coverage or rely on the coverage helper.
- If testing the guard, assert UnsupportedOperationException rather than trying to succeed.
- Remove reflective newInstance() calls against CloseUtils.class.
Defensive patterns
Strategy: validation
Validate before calling
// Never instantiate; call static methods directly. CloseUtils.closeIO(stream);
Try / catch
try {
Constructor<CloseUtils> c = CloseUtils.class.getDeclaredConstructor();
c.setAccessible(true);
c.newInstance();
} catch (UnsupportedOperationException | InvocationTargetException e) {
// expected: instantiation is forbidden by design
} Prevention
- Call CloseUtils 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 helper classes.
Common situations: Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests across a package; DI/serialization frameworks attempting default 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/c96602d09f7099de.
Report an issue: GitHub.