{"record":{"id":"2bb6ed62157fe5a0","repo":"asLody/VirtualApp","slug":"connection-is-null","errorCode":null,"errorMessage":"connection is null","messagePattern":"connection is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/secondary/ServiceConnectionDelegate.java","lineNumber":38,"sourceCode":"import mirror.android.app.IServiceConnectionO;\nimport mirror.android.app.LoadedApk;\n\n/**\n * @author Lody\n */\n\npublic class ServiceConnectionDelegate extends IServiceConnection.Stub {\n    private final static ArrayMap<IBinder, ServiceConnectionDelegate> DELEGATE_MAP = new ArrayMap<>();\n    private IServiceConnection mConn;\n\n    private ServiceConnectionDelegate(IServiceConnection mConn) {\n        this.mConn = mConn;\n    }\n\n    public static IServiceConnection getDelegate(Context context, ServiceConnection connection,int flags) {\n        IServiceConnection sd = null;\n        if (connection == null) {\n            throw new IllegalArgumentException(\"connection is null\");\n        }\n        try {\n            Object activityThread = ActivityThread.currentActivityThread.call();\n            Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());\n            Handler handler = ActivityThread.getHandler.call(activityThread);\n            sd = LoadedApk.getServiceDispatcher.call(loadApk, connection, context, handler, flags);\n        } catch (Exception e) {\n            Log.e(\"ConnectionDelegate\", \"getServiceDispatcher\", e);\n        }\n        if (sd == null) {\n            throw new RuntimeException(\"Not supported in system context\");\n        }\n        return getDelegate(sd);\n    }\n\n    public static IServiceConnection removeDelegate(Context context, ServiceConnection conn) {\n        IServiceConnection connection = null;\n        try{","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/secondary/ServiceConnectionDelegate.java#L20-L56","documentation":"ServiceConnectionDelegate.getDelegate() wraps an app's ServiceConnection into an IServiceConnection binder stub. A null ServiceConnection cannot be dispatched to, so the method throws IllegalArgumentException before any binder work is attempted.","triggerScenarios":"Calling bindService (in the VA environment) with a null ServiceConnection parameter, which forwards null into getDelegate().","commonSituations":"Variable holding the connection not yet assigned (race with async init); caller mistakenly passing null to 'unbind-like' reuse of the helper; refactored code dropping the connection argument.","solutions":["Always pass a real ServiceConnection instance when binding a service","Construct the ServiceConnection before calling bindService, not inside its callback","Null-check your connection variable at the call site"],"exampleFix":"// before\nServiceConnection conn = null; context.bindService(intent, conn, flags);\n// after\nServiceConnection conn = new ServiceConnection() {\n    @Override public void onServiceConnected(ComponentName n, IBinder s) { }\n    @Override public void onServiceDisconnected(ComponentName n) { }\n};\ncontext.bindService(intent, conn, flags);","handlingStrategy":"validation","validationCode":"if (connection == null) throw new IllegalStateException(\"ServiceConnection must be created before bindService\");","typeGuard":null,"tryCatchPattern":"try { bindService(intent, conn, flags); } catch (IllegalArgumentException e) { Log.e(TAG, \"null connection\", e); }","preventionTips":["Create the ServiceConnection object before initiating the bind","Avoid mutable connection fields set asynchronously","Initialize connections in onCreate rather than lazily"],"tags":["android","service","null-argument"],"backgroundTag":"null-argument","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}