{"record":{"id":"00e9f3a1a4aa255e","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-00e9f3","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/DebouncingUtils.java","lineNumber":28,"sourceCode":"\nimport androidx.annotation.NonNull;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2020/09/01\n *     desc  : utils about debouncing\n * </pre>\n */\npublic class DebouncingUtils {\n\n    private static final int               CACHE_SIZE               = 64;\n    private static final Map<String, Long> KEY_MILLIS_MAP           = new ConcurrentHashMap<>(CACHE_SIZE);\n    private static final long              DEBOUNCING_DEFAULT_VALUE = 1000;\n\n    private DebouncingUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Return whether the view is not in a jitter state.\n     *\n     * @param view The view.\n     * @return {@code true}: yes<br>{@code false}: no\n     */\n    public static boolean isValid(@NonNull final View view) {\n        return isValid(view, DEBOUNCING_DEFAULT_VALUE);\n    }\n\n    /**\n     * Return whether the view is not in a jitter state.\n     *\n     * @param view     The view.\n     * @param duration The duration.\n     * @return {@code true}: yes<br>{@code false}: no","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/DebouncingUtils.java#L10-L46","documentation":"DebouncingUtils is a utility class (note: declared `class`, not `final class`, but still static-only) whose private constructor throws UnsupportedOperationException(\"u can't instantiate me...\"). It provides view/key-based debouncing through static isValid(...) methods backed by a ConcurrentHashMap, so construction is neither needed nor allowed.","triggerScenarios":"Reflective construction of the class, or a generic factory/serializer that walks and instantiates types. A direct `new DebouncingUtils()` fails to compile due to the private constructor, so the runtime throw only appears via reflection.","commonSituations":"Code-coverage tools that instantiate all classes; reflective object mappers; a developer who expects instance state per-view; DI containers that try to provide utility beans.","solutions":["Use the static API: DebouncingUtils.isValid(view) or isValid(key, duration) — there is no per-instance state to create.","Add the class to the exclusion list of any tool that reflectively instantiates classes.","In a contract unit test, expect UnsupportedOperationException from the reflected constructor."],"exampleFix":"// before (reflection)\nDebouncingUtils du = DebouncingUtils.class.getDeclaredConstructor().newInstance();\n\n// after\nif (DebouncingUtils.isValid(button)) { /* handle click */ }","handlingStrategy":"validation","validationCode":"// Never construct DebouncingUtils; it is static-only.\nif (clazz == DebouncingUtils.class) {\n    // skip instantiation; call DebouncingUtils.isValid(view) statically\n}","typeGuard":"if (clazz.getName().endsWith(\"Utils\")) {\n    // static-only; do not newInstance()\n}","tryCatchPattern":"try {\n    Constructor<?> c = DebouncingUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException e) {\n    // expected; use DebouncingUtils.isValid(...) instead\n}","preventionTips":["DebouncingUtils holds its state in static fields — there is no per-instance value.","Prefer the View overload isValid(view) which derives the key for you.","Exclude 'Utils' classes from coverage/DI tools that instantiate every class."],"tags":["utility-class","instantiation","design-pattern","reflection","debounce"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}