Justson/AgentWeb · error · UnsupportedOperationException

u can't instantiate me...

Error message

u can't instantiate me...

What it means

RomUtils is a static utility class for ROM/vendor detection (Huawei EMUI, etc.); its private constructor throws UnsupportedOperationException. It exists only to expose static methods, so instantiation is intentionally blocked.

Solutions

  1. Use the static methods directly, e.g. RomUtils.isHuawei() (no instance needed)
  2. Exclude RomUtils from any reflection-based instantiation/coverage tooling
  3. Copy the needed static helper into your own code if you require an instance-style API

Example fix

// before
RomUtils romUtils = new RomUtils();
boolean huawei = romUtils.isHuawei();
// after
boolean huawei = RomUtils.isHuawei();
Defensive patterns

Strategy: type-guard

Try / catch

try {
    new RomUtils();
} catch (UnsupportedOperationException e) {
    // utility class: use static methods like RomUtils.isHuawei()
}

Prevention

When it happens

Trigger: Calling `new RomUtils()` in application code, or reflection-based construction (newInstance, serialization, bytecode tools) that invokes the private constructor.

Common situations: Instantiating utility classes by habit; frameworks or test tooling that reflectively construct all classes; misuse after refactoring instance-style helpers into static ones.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of Justson/AgentWeb@8f7f6adbf0 (2026-09-11). Data as JSON: /api/errors/a3520a1e99428761. Report an issue: GitHub.

Appendix: source

Thrown at agentweb-core/src/main/java/com/just/agentweb/RomUtils.java:34

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2018/07/04
 *     desc  : utils about rom
 * </pre>
 */
public final class RomUtils {

    private static final String[] ROM_HUAWEI    = {"huawei"};
    private static final String VERSION_PROPERTY_HUAWEI  = "ro.build.version.emui";
    private final static String UNKNOWN                  = "unknown";

    private static RomInfo bean = null;

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

    /**
     * Return whether the rom is made by huawei.
     *
     * @return {@code true}: yes<br>{@code false}: no
     */
    public static boolean isHuawei() {
        return ROM_HUAWEI[0].equals(getRomInfo().name);
    }

    /**
     * Return the rom's information.
     *
     * @return the rom's information
     */
    public static RomInfo getRomInfo() {
        if (bean != null) return bean;

View on GitHub (pinned to 8f7f6adbf0)