Blankj/AndroidUtilCode · info · UnsupportedOperationException

u can't instantiate me...

Error message

u can't instantiate me...

What it means

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.

Source

Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/DebouncingUtils.java:28

import androidx.annotation.NonNull;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2020/09/01
 *     desc  : utils about debouncing
 * </pre>
 */
public class DebouncingUtils {

    private static final int               CACHE_SIZE               = 64;
    private static final Map<String, Long> KEY_MILLIS_MAP           = new ConcurrentHashMap<>(CACHE_SIZE);
    private static final long              DEBOUNCING_DEFAULT_VALUE = 1000;

    private DebouncingUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * Return whether the view is not in a jitter state.
     *
     * @param view The view.
     * @return {@code true}: yes<br>{@code false}: no
     */
    public static boolean isValid(@NonNull final View view) {
        return isValid(view, DEBOUNCING_DEFAULT_VALUE);
    }

    /**
     * Return whether the view is not in a jitter state.
     *
     * @param view     The view.
     * @param duration The duration.
     * @return {@code true}: yes<br>{@code false}: no

View on GitHub (pinned to 7b4caf9e54)

Solutions

  1. Use the static API: DebouncingUtils.isValid(view) or isValid(key, duration) — there is no per-instance state to create.
  2. Add the class to the exclusion list of any tool that reflectively instantiates classes.
  3. In a contract unit test, expect UnsupportedOperationException from the reflected constructor.

Example fix

// before (reflection)
DebouncingUtils du = DebouncingUtils.class.getDeclaredConstructor().newInstance();

// after
if (DebouncingUtils.isValid(button)) { /* handle click */ }
Defensive patterns

Strategy: validation

Validate before calling

// Never construct DebouncingUtils; it is static-only.
if (clazz == DebouncingUtils.class) {
    // skip instantiation; call DebouncingUtils.isValid(view) statically
}

Type guard

if (clazz.getName().endsWith("Utils")) {
    // static-only; do not newInstance()
}

Try / catch

try {
    Constructor<?> c = DebouncingUtils.class.getDeclaredConstructor();
    c.setAccessible(true);
    c.newInstance();
} catch (UnsupportedOperationException e) {
    // expected; use DebouncingUtils.isValid(...) instead
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14). Data as JSON: /api/errors/00e9f3a1a4aa255e. Report an issue: GitHub.