fix(mock): throw on interaction with null target - #2402
Conversation
Declaring an interaction on a null target is invalid and was previously silent (or could NPE with some mock makers). Reject it early with InvalidSpecException so users get a clear error. Fixes spockframework#2339
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughInteractions declared on ChangesNull interaction validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR rejects mock interactions whose evaluated target is
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The new validation applies uniformly through the shared interaction-target construction path, preserves wildcard interactions through their non-null sentinel, and is covered for both stubbing and required interactions. Important Files Changed
Reviews (1): Last reviewed commit: "fix(mock): throw on interaction with nul..." | Re-trigger Greptile |
|
Hi @arimu1, Version 3.0 is not planed yet. |
Summary
Declaring an interaction on a
nulltarget (for example after an unstubbed mock chain returnsnull) is invalid. Previously Spock accepted such interactions silently, which made the mistake hard to notice. Some mock makers also failed with an unrelated NPE (see #2337).This change rejects a
nullinteraction target withInvalidSpecExceptionand the messageInteraction on a null object is invalid.AI assistance: Used for issue research and drafting the change; the design follows existing
InvalidSpecExceptionvalidation inTargetConstraint/InteractionBuilder, and the tests were run locally.Changes
TargetConstraint: throwInvalidSpecExceptionwhen the target isnullTesting
Result: BUILD SUCCESSFUL (Temurin 21 Gradle JVM, Java 8 toolchain for the variant).
Fixes #2339