{"record":{"id":"6554434526ed50c1","repo":"Justson/AgentWeb","slug":"u-can-t-init-me","errorCode":null,"errorMessage":"u can't init me","messagePattern":"u can't init me","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java","lineNumber":98,"sourceCode":"import java.util.List;\nimport java.util.Locale;\nimport java.util.Map;\n\nimport static com.just.agentweb.AgentWebConfig.AGENTWEB_FILE_PATH;\nimport static com.just.agentweb.AgentWebConfig.FILE_CACHE_PATH;\n\n\n/**\n * @author cenxiaozhong\n * @since 1.0.0\n */\npublic class AgentWebUtils {\n\n\tprivate static final String TAG = AgentWebUtils.class.getSimpleName();\n\tprivate static Handler mHandler = null;\n\n\tprivate AgentWebUtils() {\n\t\tthrow new UnsupportedOperationException(\"u can't init me\");\n\t}\n\n\tpublic static int dp2px(Context context, float dipValue) {\n\t\tfinal float scale = context.getResources().getDisplayMetrics().density;\n\t\treturn (int) (dipValue * scale + 0.5f);\n\t}\n\n\tstatic final void clearWebView(WebView m) {\n\t\tif (m == null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Looper.myLooper() != Looper.getMainLooper()) {\n\t\t\treturn;\n\t\t}\n\t\tm.loadUrl(\"about:blank\");\n\t\tm.stopLoading();\n\t\tif (m.getHandler() != null) {\n\t\t\tm.getHandler().removeCallbacksAndMessages(null);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/Justson/AgentWeb/blob/8f7f6adbf01010e9b2b44638f31edf10e1ba53f7/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java#L80-L116","documentation":"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.","triggerScenarios":"Calling `new AgentWebUtils()` from application code, or using reflection (e.g. Class.newInstance(), frameworks instantiating classes via reflection) that reaches the private constructor.","commonSituations":"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.","solutions":["Do not instantiate AgentWebUtils; call its static methods directly, e.g. AgentWebUtils.dp2px(context, 10f)","If a reflection-based tool constructs it, exclude this class or mark it un-instantiable in the tool's config","If instantiation is genuinely needed, extend the class or copy the needed static helper into your own utility class"],"exampleFix":"// before\nAgentWebUtils utils = new AgentWebUtils();\nint px = utils.dp2px(context, 10f);\n// after\nint px = AgentWebUtils.dp2px(context, 10f);","handlingStrategy":"type-guard","validationCode":"// never instantiate; verify usage\nif (instance instanceof AgentWebUtils) { /* misuse: use AgentWebUtils.dp2px(...) instead */ }","typeGuard":null,"tryCatchPattern":"try {\n    AgentWebUtils.class.getDeclaredConstructor().setAccessible(true);\n    AgentWebUtils.class.getDeclaredConstructor().newInstance();\n} catch (UnsupportedOperationException | ReflectiveOperationException e) {\n    // expected: utility class is not instantiable; switch to static method calls\n}","preventionTips":["Treat classes with private constructors throwing UnsupportedOperationException as static-only APIs","Call static helpers directly on the class name, never via an instance","Configure lint/IDE inspections to flag instantiation of utility classes","Exclude utility classes from reflection-driven code that instantiates all classes"],"tags":["java","android","instantiation","utility-class"],"backgroundTag":"unsupported-operation","analyzedSha":"8f7f6adbf01010e9b2b44638f31edf10e1ba53f7","analyzedAt":"2026-09-11T10:05:24.337Z","contentChangedAt":"2026-09-11T10:05:24.337Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}