Blankj/AndroidUtilCode · info · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
ClipboardUtils is a final utility class with static clipboard 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/ClipboardUtils.java:19
package com.blankj.utilcode.util;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/09/25
* desc : utils about clipboard
* </pre>
*/
public final class ClipboardUtils {
private ClipboardUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Copy the text to clipboard.
* <p>The label equals name of package.</p>
*
* @param text The text.
*/
public static void copyText(final CharSequence text) {
ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);
//noinspection ConstantConditions
cm.setPrimaryClip(ClipData.newPlainText(Utils.getApp().getPackageName(), text));
}
/**
* Copy the text to clipboard.
*
* @param label The label.View on GitHub (pinned to 7b4caf9e54)
Solutions
- Call static methods directly (e.g., ClipboardUtils.copyText(text)) 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 ClipboardUtils.class.
Defensive patterns
Strategy: validation
Validate before calling
// Never instantiate; call static methods directly. ClipboardUtils.copyText(text);
Try / catch
try {
Constructor<ClipboardUtils> c = ClipboardUtils.class.getDeclaredConstructor();
c.setAccessible(true);
c.newInstance();
} catch (UnsupportedOperationException | InvocationTargetException e) {
// expected: instantiation is forbidden by design
} Prevention
- Call ClipboardUtils 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/89d3dbb987397bd2.
Report an issue: GitHub.