fix: handle invalid namesrv instance endpoints#10648
Open
Loyal-Young wants to merge 2 commits into
Open
Conversation
Loyal-Young
marked this pull request as ready for review
July 22, 2026 15:57
RockteMQ-AI
approved these changes
Jul 22, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Defensive fix that prevents NullPointerException in validateInstanceEndpoint and StringIndexOutOfBoundsException in parseInstanceIdFromEndpoint when given null or non-instance endpoints.
Findings
- [Positive]
NameServerAddressUtils.java:31— AddingStringUtils.isNotEmpty(endpoint)guard beforeINST_ENDPOINT_PATTERN.matcher(endpoint)correctly prevents NPE on null input. - [Positive]
NameServerAddressUtils.java:35— Delegating tovalidateInstanceEndpoint()instead of justStringUtils.isEmpty()is the right approach. Previously, a non-empty but non-instance endpoint like"abc"(no dot) would causeindexOf(".")to return -1, leading tosubstring(0, -1)→StringIndexOutOfBoundsException. Now only regex-validated instance endpoints proceed to parsing. - [Info]
NameServerAddressUtils.java:35— This is a subtle behavioral change:parseInstanceIdFromEndpoint("127.0.0.1:9876")previously returned"127"(garbage), now returnsnull. Callers that relied on the old behavior (if any) would need to handle null. Given the old return was meaningless, this is the correct fix. - [Positive]
NameServerAddressUtilsTest.java— Good test coverage additions: null validation test and non-instance endpoint parsing tests (endpoint1,endpoint2).
Suggestions
- Consider adding a test case for
parseInstanceIdFromEndpoint(null)to explicitly verify null safety on the parsing path as well.
Verdict
Clean, well-scoped bug fix with appropriate test coverage. LGTM.
Automated review by github-manager-bot
RockteMQ-AI
approved these changes
Jul 22, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot (Follow-up)
New Commit: test: cover null namesrv instance parsing
The new commit addresses the previous review suggestion by adding explicit null-safety test coverage for parseInstanceIdFromEndpoint(null).
Changes
NameServerAddressUtilsTest.java— Added test cases:validateInstanceEndpoint(null)→false✓parseInstanceIdFromEndpoint(null)→null✓parseInstanceIdFromEndpoint(endpoint1)→null(non-instance endpoint) ✓parseInstanceIdFromEndpoint(endpoint2)→null(non-instance endpoint) ✓
Verdict
New commit cleanly addresses the review suggestion. No new issues found. Still LGTM.
Automated review by github-manager-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validateInstanceEndpointreturnfalsefor a null endpointnullwhenparseInstanceIdFromEndpointreceives an invalid non-empty endpointWhy
The parser previously used string indexes on any non-empty input. A normal NameServer address that is not an instance endpoint could therefore throw
StringIndexOutOfBoundsException.Impact
Valid instance endpoints retain their existing parsed instance ID. Invalid or non-instance endpoints now fail safely with
null.Validation
git diff --checkmvn -pl common -Dtest=NameServerAddressUtilsTest test