Validate condition router YAML before parsing - #16446
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16446 +/- ##
============================================
- Coverage 60.91% 60.89% -0.03%
- Complexity 15 11745 +11730
============================================
Files 1953 1953
Lines 89271 89274 +3
Branches 13473 13474 +1
============================================
- Hits 54383 54360 -23
- Misses 29309 29328 +19
- Partials 5579 5586 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LI123456mo
left a comment
There was a problem hiding this comment.
Verified the fix — yaml.load() can return null/non-Map for bad input, old code cast blindly (NPE/CCE), new instanceof Map check + clear exception is correct.
Note: testRejectNonMappingRule actually proves the fix (fails on old code). testCommentOnlyRuleUpdatePreservesPreviousRule passes either way — ListenableStateRouter.process() already has a try/catch around the parse & assign, so routerRule was never actually at risk of getting nulled out, worth checking that @minnnjuuu . PR description overstates that part a bit — real value here is clearer error messages, not data-loss prevention. Not a blocker.
LGTM , @zrlw
|
Thanks for pointing this out. You're right: the right-hand side of the assignment is evaluated before I've updated the PR description to focus on explicit YAML validation and clearer exception reporting, and removed the redundant state-preservation test. |
|
@minnnjuuu , your test classes are well you can keep both for test purposes, the only issue was the description which you have already modified it clearly |
What is the purpose of the change?
ConditionRuleParser.parse()assumes that SnakeYAML always returns a YAML mapping. However, an empty YAML document returnsnull, while a sequence or scalar document returns a non-map value. This can result in aNullPointerExceptionorClassCastExceptioninstead of a clear validation error.Some configuration-center adapters filter a Java
nullor an exactly empty string, but that does not cover every input that produces a null SnakeYAML result. Non-empty inputs such as a comment-only document,---, or the explicit YAML valuenullcan pass string-level checks and still load asnull.This change validates the top-level YAML value before parsing it and rejects non-mapping documents with a clear
IllegalArgumentExceptioninstead of relying on incidentalNullPointerExceptionorClassCastExceptionfailures.What does this change do?
Objectbefore casting it.IllegalArgumentExceptionfor empty, comment-only, sequence, and scalar documents.Checklist