{"record":{"id":"89d3dbb987397bd2","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-89d3db","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/ClipboardUtils.java","lineNumber":19,"sourceCode":"package com.blankj.utilcode.util;\n\nimport android.content.ClipData;\nimport android.content.ClipDescription;\nimport android.content.ClipboardManager;\nimport android.content.Context;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/09/25\n *     desc  : utils about clipboard\n * </pre>\n */\npublic final class ClipboardUtils {\n\n    private ClipboardUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Copy the text to clipboard.\n     * <p>The label equals name of package.</p>\n     *\n     * @param text The text.\n     */\n    public static void copyText(final CharSequence text) {\n        ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);\n        //noinspection ConstantConditions\n        cm.setPrimaryClip(ClipData.newPlainText(Utils.getApp().getPackageName(), text));\n    }\n\n    /**\n     * Copy the text to clipboard.\n     *\n     * @param label The label.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/ClipboardUtils.java#L1-L37","documentation":"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.","triggerScenarios":"Reflectively invoking the private constructor (setAccessible(true) + newInstance()); coverage or generic reflection tooling that instantiates every class; frameworks that auto-construct helper classes.","commonSituations":"Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests across a package; DI/serialization frameworks attempting default construction.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Never instantiate; call static methods directly.\nClipboardUtils.copyText(text);","typeGuard":null,"tryCatchPattern":"try {\n    Constructor<ClipboardUtils> c = ClipboardUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException | InvocationTargetException e) {\n    // expected: instantiation is forbidden by design\n}","preventionTips":["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."],"tags":["utility-class","private-constructor","reflection","clipboardutils","android","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}