Repository navigation
[type: bug] Fix namespaceId null handling in AbstractNodeDataChangedListener (#6876) - #7010
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Review: Fix namespaceId null handling in AbstractNodeDataChangedListener (#6876)
Verdict: APPROVE
Analysis
In onSelectorChanged, the configKeyPrefix was built directly from selectorData.getNamespaceId() with no null guard:
final String configKeyPrefix = selectorData.getNamespaceId() + DefaultNodeConstants.JOIN_POINT + ...When namespaceId is null, the prefix started with the literal "null" + JOIN_POINT, producing a wrong config key (and inconsistent with selectors that legitimately belong to the system default namespace).
The fix uses the same fallback already applied consistently throughout this class:
final String configKeyPrefix = StringUtils.defaultString(selectorData.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID) + ...SYS_DEFAULT_NAMESPACE_IDis statically imported (org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID) and is the same value used byonSelectorChanged's sibling methods (lines 73/84/95/187/290/301 already useStringUtils.defaultString(value.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID)), so the key schema stays consistent.org.apache.commons.lang3.StringUtilsis already imported.
No production caller relies on the previous "null"-prefixed key (that was a bug), and the rest of the onCommonMultiChanged flow is unchanged.
Conclusion
Minimal, consistent with existing conventions, and removes a real null-handling bug. Approving.
|
Rebased onto latest master, conflicts resolved |
fd9803d to
2ee5c48
Compare
Aias00
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES (PMC Aias00): the main build job is failing — this PR does not compile/pass tests, so it cannot be merged. Please fix the compilation/test failures and re-run CI, then request a re-review.
…istener (apache#6876) Signed-off-by: zhang-arvin <[email protected]>
d619122 to
ae1b03b
Compare
|
@Aias00 Thanks for the review. The branch was 37 commits behind Would you mind re-running the checks / taking another look? |
Aias00
left a comment
There was a problem hiding this comment.
Approving — this is a small but real correctness fix, and it makes the method consistent with the rest of the file.
onSelectorChanged built its config-key prefix directly from selectorData.getNamespaceId(). When that field was null (selector synced without a namespace — e.g. legacy data or a sync path that didn't populate it), the key became literally null.<selectorId>., so the node wrote config under a key no reader would ever look up, and the selector silently failed to propagate.
StringUtils.defaultString(..., SYS_DEFAULT_NAMESPACE_ID) is exactly the right fix, and it is also consistent: I checked the branch and the same defaultString(value.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID) pattern is already used at lines 73, 84, 95, 187, 290 and 301 of this very class. Line 177 was simply the one place that missed it, which is a good sign this is a genuine oversight rather than a design choice.
Verified the symbols resolve on this branch: org.apache.commons.lang3.StringUtils (line 20), DefaultNodeConstants (line 21) and the static import of Constants.SYS_DEFAULT_NAMESPACE_ID (line 46) are all present, so no import changes were needed.
One non-blocking suggestion: this method now has no test. A case that pushes a SelectorData with a null namespaceId and asserts the resulting key starts with the default namespace id would pin the fix — the surrounding methods have similar coverage gaps, so this is a nice-to-have rather than a blocker.
…angedListener Line 177 exceeded the 200-character limit (223 chars) after adding the namespaceId default. Wrap the config-key concatenation onto two lines.
|
add my wechat: aias00 |
Closes #6876