{"record":{"id":"be8ff6eeb4d7e967","repo":"umano/AndroidSlidingUpPanel","slug":"callback-may-not-be-null","errorCode":null,"errorMessage":"Callback may not be null","messagePattern":"Callback may not be null","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java","lineNumber":409,"sourceCode":"        return helper;\n    }\n\n    /**\n     * Apps should use ViewDragHelper.create() to get a new instance.\n     * This will allow VDH to use internal compatibility implementations for different\n     * platform versions.\n     * If the interpolator is null, the default interpolator will be used.\n     *\n     * @param context Context to initialize config-dependent params from\n     * @param forParent Parent view to monitor\n     * @param interpolator interpolator for scroller\n     */\n    private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interpolator, Callback cb) {\n        if (forParent == null) {\n            throw new IllegalArgumentException(\"Parent view may not be null\");\n        }\n        if (cb == null) {\n            throw new IllegalArgumentException(\"Callback may not be null\");\n        }\n\n        mParentView = forParent;\n        mCallback = cb;\n\n        final ViewConfiguration vc = ViewConfiguration.get(context);\n        final float density = context.getResources().getDisplayMetrics().density;\n        mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);\n\n        mTouchSlop = vc.getScaledTouchSlop();\n        mMaxVelocity = vc.getScaledMaximumFlingVelocity();\n        mMinVelocity = vc.getScaledMinimumFlingVelocity();\n        mScroller = ScrollerCompat.create(context, interpolator != null ? interpolator : sInterpolator);\n    }\n\n    /**\n     * Set the minimum velocity that will be detected as having a magnitude greater than zero\n     * in pixels per second. Callback methods accepting a velocity will be clamped appropriately.","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java#L391-L427","documentation":"A validation guard in ViewDragHelper's private constructor: it rejects a null Callback parameter. The Callback is essential — ViewDragHelper delegates all drag behavior (which child can be dragged, clamp positions, onDrag/onRelease notifications) to it, so a helper without one is unusable and would NPE later during touch events. It fires when a caller passes null for the cb argument, e.g. calling the private constructor directly or a factory wrapper that forwards an uninitialized callback. Note the constructor is private by design; apps must use ViewDragHelper.create(), which always requires a non-null Callback. Fix: pass a real Callback subclass instance (e.g. a ViewDragHelper.Callback overriding tryCaptureView).","triggerScenarios":"Calling ViewDragHelper.create(parent, null) or passing a callback field that is still null (e.g. set later in a lifecycle callback that hasn't run).","commonSituations":"Kotlin lateinit/Java field callbacks not yet assigned; refactoring where the callback was removed but the create call retained the now-null reference.","solutions":["Pass a concrete Callback implementation to create()","Construct the callback inline or before helper creation","Verify initialization order of fields"],"exampleFix":"// before\nmDragHelper = ViewDragHelper.create(this, mCallback); // mCallback is null\n// after\nmDragHelper = ViewDragHelper.create(this, new ViewDragHelper.Callback() { ... });","handlingStrategy":"type-guard","validationCode":"if (callback == null) throw new AssertionError(\"callback required\");\nmDragHelper = ViewDragHelper.create(this, callback);","typeGuard":"ViewDragHelper.Callback requireCb(ViewDragHelper.Callback cb) { return cb != null ? cb : defaultCallback; }","tryCatchPattern":null,"preventionTips":["Construct the Callback before the helper","Avoid lateinit/nullable callback fields","Pass anonymous Callback inline"],"tags":["android","viewdraghelper","null-argument","callback"],"backgroundTag":"null-argument","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}