Justson/AgentWeb · error · UnsupportedOperationException

u can't init me

Error message

u can't init me

What it means

AgentWebUtils is a static utility-only class; its private constructor deliberately throws UnsupportedOperationException. The library authors want to prevent instantiation (e.g. `new AgentWebUtils()`) and reflection-based construction, forcing callers to use the static helper methods like dp2px() directly.

Solutions

  1. Do not instantiate AgentWebUtils; call its static methods directly, e.g. AgentWebUtils.dp2px(context, 10f)
  2. If a reflection-based tool constructs it, exclude this class or mark it un-instantiable in the tool's config
  3. If instantiation is genuinely needed, extend the class or copy the needed static helper into your own utility class

Example fix

// before
AgentWebUtils utils = new AgentWebUtils();
int px = utils.dp2px(context, 10f);
// after
int px = AgentWebUtils.dp2px(context, 10f);
Defensive patterns

Strategy: type-guard

Validate before calling

// never instantiate; verify usage
if (instance instanceof AgentWebUtils) { /* misuse: use AgentWebUtils.dp2px(...) instead */ }

Try / catch

try {
    AgentWebUtils.class.getDeclaredConstructor().setAccessible(true);
    AgentWebUtils.class.getDeclaredConstructor().newInstance();
} catch (UnsupportedOperationException | ReflectiveOperationException e) {
    // expected: utility class is not instantiable; switch to static method calls
}

Prevention

When it happens

Trigger: Calling `new AgentWebUtils()` from application code, or using reflection (e.g. Class.newInstance(), frameworks instantiating classes via reflection) that reaches the private constructor.

Common situations: Developers habitually instantiate utility classes; code generators or DI/reflection tools scanning the classpath try to construct every public class; copying a pattern from a non-utility class.

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/6554434526ed50c1. Report an issue: GitHub.

Appendix: source

Thrown at agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java:98

import java.util.List;
import java.util.Locale;
import java.util.Map;

import static com.just.agentweb.AgentWebConfig.AGENTWEB_FILE_PATH;
import static com.just.agentweb.AgentWebConfig.FILE_CACHE_PATH;


/**
 * @author cenxiaozhong
 * @since 1.0.0
 */
public class AgentWebUtils {

	private static final String TAG = AgentWebUtils.class.getSimpleName();
	private static Handler mHandler = null;

	private AgentWebUtils() {
		throw new UnsupportedOperationException("u can't init me");
	}

	public static int dp2px(Context context, float dipValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}

	static final void clearWebView(WebView m) {
		if (m == null) {
			return;
		}
		if (Looper.myLooper() != Looper.getMainLooper()) {
			return;
		}
		m.loadUrl("about:blank");
		m.stopLoading();
		if (m.getHandler() != null) {
			m.getHandler().removeCallbacksAndMessages(null);

View on GitHub (pinned to 8f7f6adbf0)