{"record":{"id":"a55c43a4b944a93c","repo":"daimajia/AndroidSwipeLayout","slug":"swipeadapterinterface-can-not-be-null","errorCode":null,"errorMessage":"SwipeAdapterInterface can not be null","messagePattern":"SwipeAdapterInterface can not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java","lineNumber":34,"sourceCode":"\n/**\n * SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.\n */\npublic class SwipeItemMangerImpl implements SwipeItemMangerInterface {\n\n    private Attributes.Mode mode = Attributes.Mode.Single;\n    public final int INVALID_POSITION = -1;\n\n    protected int mOpenPosition = INVALID_POSITION;\n\n    protected Set<Integer> mOpenPositions = new HashSet<Integer>();\n    protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();\n\n    protected SwipeAdapterInterface swipeAdapterInterface;\n\n    public SwipeItemMangerImpl(SwipeAdapterInterface swipeAdapterInterface) {\n        if (swipeAdapterInterface == null)\n            throw new IllegalArgumentException(\"SwipeAdapterInterface can not be null\");\n\n        this.swipeAdapterInterface = swipeAdapterInterface;\n    }\n\n    public Attributes.Mode getMode() {\n        return mode;\n    }\n\n    public void setMode(Attributes.Mode mode) {\n        this.mode = mode;\n        mOpenPositions.clear();\n        mShownLayouts.clear();\n        mOpenPosition = INVALID_POSITION;\n    }\n\n    public void bind(View view, int position) {\n        int resId = swipeAdapterInterface.getSwipeLayoutResourceId(position);\n        SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(resId);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/daimajia/AndroidSwipeLayout/blob/5f8678b04751fb8510a88586b22e07ccf64bca99/library/src/main/java/com/daimajia/swipe/implments/SwipeItemMangerImpl.java#L16-L52","documentation":"SwipeItemMangerImpl's constructor requires a non-null SwipeAdapterInterface, which it delegates to for swipe layout resource ids and modes. Passing null leaves the manager unable to operate, so the constructor throws IllegalArgumentException immediately.","triggerScenarios":"Constructing SwipeItemMangerImpl (directly or via a subclass like SwipeItemAdapterMangerImpl / BaseSwipeAdapter) with a null SwipeAdapterInterface argument, e.g. an uninitialized adapter field passed to the manager.","commonSituations":"Custom adapter sets up the manager in a field initializer before the adapter reference is ready; passing null in tests; subclass forgets to call super(adapter) with a real adapter.","solutions":["Pass the adapter itself (this) when constructing the manager inside a BaseSwipeAdapter subclass","Ensure the adapter field is initialized before the manager is constructed","Never pass null; construct the manager lazily after the adapter is available"],"exampleFix":"// before\nclass MyAdapter extends BaseSwipeAdapter {\n    SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(null);\n}\n// after\nclass MyAdapter extends BaseSwipeAdapter {\n    SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);\n}","handlingStrategy":"validation","validationCode":"if (adapter == null) {\n    throw new IllegalArgumentException(\"adapter must be initialized before creating SwipeItemMangerImpl\");\n}\nSwipeItemMangerImpl manager = new SwipeItemMangerImpl(adapter);","typeGuard":null,"tryCatchPattern":"try {\n    this.mItemManger = new SwipeItemMangerImpl(this);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"SwipeItemMangerImpl requires a non-null adapter\", e);\n}","preventionTips":["Always construct the manager with 'this' inside BaseSwipeAdapter subclasses","Avoid initializing manager fields before adapter dependencies are ready","Add constructor-time null assertions in custom adapters"],"tags":["android","null-check","constructor","adapter"],"backgroundTag":"null-argument","analyzedSha":"5f8678b04751fb8510a88586b22e07ccf64bca99","analyzedAt":"2026-09-08T03:35:37.231Z","contentChangedAt":"2026-09-08T03:35:37.231Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}