{"record":{"id":"0760d9ffc286747e","repo":"Justson/AgentWeb","slug":"injected-name-can-not-be-null","errorCode":null,"errorMessage":"injected name can not be null","messagePattern":"injected name can not be null","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"agentweb-core/src/main/java/com/just/agentweb/JsCallJava.java","lineNumber":47,"sourceCode":"\npublic class JsCallJava {\n    private final static String TAG = \"JsCallJava\";\n    private final static String RETURN_RESULT_FORMAT = \"{\\\"CODE\\\": %d, \\\"result\\\": %s}\";\n    private static final String MSG_PROMPT_HEADER = \"AgentWeb:\";\n    private static final String KEY_OBJ = \"obj\";\n    private static final String KEY_METHOD = \"method\";\n    private static final String KEY_TYPES = \"types\";\n    private static final String KEY_ARGS = \"args\";\n    private static final String[] IGNORE_UNSAFE_METHODS = {\"getClass\", \"hashCode\", \"notify\", \"notifyAll\", \"equals\", \"toString\", \"wait\"};\n    private HashMap<String, Method> mMethodsMap;\n    private Object mInterfaceObj;\n    private String mInterfacedName;\n    private String mPreloadInterfaceJs;\n\n    public JsCallJava(Object interfaceObj, String interfaceName) {\n        try {\n            if (TextUtils.isEmpty(interfaceName)) {\n                throw new Exception(\"injected name can not be null\");\n            }\n            mInterfaceObj = interfaceObj;\n            mInterfacedName = interfaceName;\n            mMethodsMap = new HashMap<String, Method>();\n            // getMethods会获得所有继承与非继承的方法\n            Method[] methods = mInterfaceObj.getClass().getMethods();\n            // 拼接的js脚本可参照备份文件：./library/doc/injected.js\n            StringBuilder sb = new StringBuilder(\"javascript:(function(b){console.log(\\\"\");\n            sb.append(mInterfacedName);\n            sb.append(\" init begin\\\");var a={queue:[],callback:function(){var d=Array.prototype.slice.call(arguments,0);var c=d.shift();var e=d.shift();this.queue[c].apply(this,d);if(!e){delete this.queue[c]}}};\");\n            for (Method method : methods) {\n                Log.i(\"Info\",\"method:\"+method);\n                String sign;\n                if ((sign = genJavaMethodSign(method)) == null) {\n                    continue;\n                }\n                mMethodsMap.put(sign, method);\n                sb.append(String.format(\"a.%s=\", method.getName()));","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/Justson/AgentWeb/blob/8f7f6adbf01010e9b2b44638f31edf10e1ba53f7/agentweb-core/src/main/java/com/just/agentweb/JsCallJava.java#L29-L65","documentation":"The JsCallJava constructor throws when the JavaScript interface name passed in is empty or null (checked via TextUtils.isEmpty). This name is the window-level object name used by injected JS, so it is mandatory. The raw Exception is caught/wrapped internally into the library's JS-bridge setup failure path.","triggerScenarios":"Calling new JsCallJava(interfaceObj, null) or with an empty string name; in AgentWeb usage, registering a Java object via the JS-injection APIs with a null/empty interface name.","commonSituations":"Building the JS bridge programmatically with a name read from config/remote data that is missing, typos where the name variable defaults to empty, or calling low-level JsCallJava directly instead of through SafeJsInterface/JavascriptInterfaceHolder helpers.","solutions":["Pass a non-empty interface name, e.g. new JsCallJava(obj, \"androidBridge\")","Validate the name string before constructing","If the name comes from config, provide a default and check emptiness at load time","Prefer AgentWeb's higher-level addJavascriptInterface APIs which handle naming"],"exampleFix":"// before\nJsCallJava js = new JsCallJava(bridge, mName); // mName may be \"\"\n// after\nif (!TextUtils.isEmpty(mName)) {\n    JsCallJava js = new JsCallJava(bridge, mName);\n}","handlingStrategy":"validation","validationCode":"if (name == null || name.trim().isEmpty()) { throw new IllegalArgumentException(\"JS interface name required\"); }","typeGuard":"boolean validJsName(String n) { return n != null && n.matches(\"[A-Za-z_$][A-Za-z0-9_$]*\"); }","tryCatchPattern":"try { new JsCallJava(obj, name); } catch (Exception e) { Log.e(TAG, \"invalid JS interface name\", e); }","preventionTips":["Hardcode or default the bridge name","Validate config-sourced names at startup","Prefer AgentWeb's higher-level interface registration APIs","Never pass user-controlled names unchecked"],"tags":["android","javascript-bridge","null-argument","js-injection"],"backgroundTag":"empty-required-field","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"}