Blankj/AndroidUtilCode · warning · UnsupportedOperationException

u can't instantiate me...

Error message

u can't instantiate me...

What it means

AppUtils (utilcode) is a final utility class whose private constructor throws UnsupportedOperationException. It exposes only static app-info helpers (install, version, status listeners); instances are forbidden.

Source

Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java:35

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2016/08/02
 *     desc  : utils about app
 * </pre>
 */
public final class AppUtils {

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

    /**
     * Register the status of application changed listener.
     *
     * @param listener The status of application changed listener
     */
    public static void registerAppStatusChangedListener(@NonNull final Utils.OnAppStatusChangedListener listener) {
        UtilsBridge.addOnAppStatusChangedListener(listener);
    }

    /**
     * Unregister the status of application changed listener.
     *
     * @param listener The status of application changed listener
     */
    public static void unregisterAppStatusChangedListener(@NonNull final Utils.OnAppStatusChangedListener listener) {
        UtilsBridge.removeOnAppStatusChangedListener(listener);

View on GitHub (pinned to 7b4caf9e54)

Solutions

  1. Use the static API, e.g. AppUtils.isAppDebug(), AppUtils.installApp(path); never instantiate.
  2. Configure reflective frameworks to skip final utility classes.
  3. Remove newInstance paths targeting AppUtils.

Example fix

// before
AppUtils a = reflectNew(AppUtils.class); // throws

// after
boolean debug = AppUtils.isAppDebug();
Defensive patterns

Strategy: validation

Validate before calling

// AppUtils is static-only; never instantiate.
boolean debug = AppUtils.isAppDebug();

Type guard

private static boolean isStaticUtility(Class<?> c) {
    return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);
}

Prevention

When it happens

Trigger: Reflective instantiation or unsafe allocation of AppUtils instead of calling its static methods.

Common situations: Reflection/DI/serialization frameworks that build arbitrary classes; tests that reflectively scaffold utilities.

Related errors


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