Skip to content

fix: handle invalid namesrv instance endpoints#10648

Open
Loyal-Young wants to merge 2 commits into
apache:developfrom
Loyal-Young:codex/handle-invalid-namesrv-endpoint
Open

fix: handle invalid namesrv instance endpoints#10648
Loyal-Young wants to merge 2 commits into
apache:developfrom
Loyal-Young:codex/handle-invalid-namesrv-endpoint

Conversation

@Loyal-Young

@Loyal-Young Loyal-Young commented Jul 22, 2026

Copy link
Copy Markdown

Summary

  • make validateInstanceEndpoint return false for a null endpoint
  • return null when parseInstanceIdFromEndpoint receives an invalid non-empty endpoint
  • cover null and normal NameServer endpoints with unit tests

Why

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 --check
  • Attempted: mvn -pl common -Dtest=NameServerAddressUtilsTest test
  • The first Maven dependency resolution exceeded the local command timeout; upstream CI is still needed for the full test result.

@Loyal-Young
Loyal-Young marked this pull request as ready for review July 22, 2026 15:57

@RockteMQ-AI RockteMQ-AI 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 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 — Adding StringUtils.isNotEmpty(endpoint) guard before INST_ENDPOINT_PATTERN.matcher(endpoint) correctly prevents NPE on null input.
  • [Positive] NameServerAddressUtils.java:35 — Delegating to validateInstanceEndpoint() instead of just StringUtils.isEmpty() is the right approach. Previously, a non-empty but non-instance endpoint like "abc" (no dot) would cause indexOf(".") to return -1, leading to substring(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 returns null. 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 RockteMQ-AI 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 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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants