minnnjuuu opened a new pull request, #16446:
URL: https://github.com/apache/dubbo/pull/16446

   ## What is the purpose of the change?
   `ConditionRuleParser.parse()` assumes that SnakeYAML always returns a YAML 
mapping. However, an empty YAML document returns `null`, while a sequence or 
scalar document returns a non-map value. This can result in a 
`NullPointerException` or `ClassCastException` instead of a clear validation 
error.
   
   Some configuration-center adapters filter a Java `null` or 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 value `null` can pass string-level checks and still load as 
`null`.
   
   Returning `null` when the document has no mapping value is also unsafe in 
this path. `ListenableStateRouter.process()` would assign that value to 
`routerRule`, unintentionally discarding the previously active rule when an 
invalid configuration update is received.
   
   This change validates the top-level YAML value before parsing it and rejects 
non-mapping documents with an `IllegalArgumentException`. Because parsing fails 
before the assignment is completed, the listener's existing error handling 
keeps the last valid routing rule active.
   
   **What does this change do?**
   
   - Parse the YAML document into an `Object` before casting it.
   - Require the top-level YAML value to be a mapping.
   - Report a clear `IllegalArgumentException` for empty, comment-only, 
sequence, and scalar documents.
   - Add regression coverage confirming that a reachable comment-only update 
does not replace the previously active rule.
   
   ## Checklist
   - [ ] Make sure there is a 
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Write necessary unit-test to verify your logic correction. If the new 
feature or significant change is committed, please remember to add sample in 
[dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [x] Make sure gitHub actions can pass. [Why the workflow is failing and 
how to fix it?](../CONTRIBUTING.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to