Skip to content

[type: bug] Fix namespaceId null handling in AbstractNodeDataChangedListener (#6876) - #7010

Merged
Aias00 merged 4 commits into
apache:masterfrom
zhang-arvin:fix/6876-namespace-id
Sep 26, 2026
Merged

Aias00 merged 4 commits into
apache:masterfrom
zhang-arvin:fix/6876-namespace-id

Conversation

@zhang-arvin

Copy link
Copy Markdown
Contributor

Closes #6876

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ID is statically imported (org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID) and is the same value used by onSelectorChanged's sibling methods (lines 73/84/95/187/290/301 already use StringUtils.defaultString(value.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID)), so the key schema stays consistent.
  • org.apache.commons.lang3.StringUtils is 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.

@zhang-arvin

Copy link
Copy Markdown
Contributor Author

Rebased onto latest master, conflicts resolved

@zhang-arvin
zhang-arvin force-pushed the fix/6876-namespace-id branch 3 times, most recently from fd9803d to 2ee5c48 Compare September 16, 2026 15:54

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zhang-arvin

Copy link
Copy Markdown
Contributor Author

@Aias00 Thanks for the review. The branch was 37 commits behind master, so I've rebased it onto the current master and force-pushed. There is no code change — the fix (StringUtils.defaultString(selectorData.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID) in onSelectorChanged, bringing it in line with the neighbouring onRuleChanged) is unchanged, and the rebase only clears the base drift.

Would you mind re-running the checks / taking another look?

Aias00
Aias00 previously approved these changes Sep 24, 2026

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Aias00
Aias00 merged commit ae08c16 into apache:master Sep 26, 2026
39 checks passed
@Aias00

Aias00 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

add my wechat: aias00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants