Skip to content

fix(common): do not throw on endpoint without dot in parseInstanceIdFromEndpoint - #11137

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/parse-instance-id-endpoint-bounds
Open

zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/parse-instance-id-endpoint-bounds

Conversation

@zjncs

@zjncs zjncs commented Sep 11, 2026

Copy link
Copy Markdown

Motivation

parseInstanceIdFromEndpoint used the result of endpoint.indexOf('.') directly as the substring end index:

return endpoint.substring(0, endpoint.indexOf('.'));

so any non-empty endpoint without a dot (for example MQ_INST_123456789_BXXUzaee:80) produced -1 and threw StringIndexOutOfBoundsException from a public utility.

Modifications

Treat a missing dot as a non-instance endpoint and return null.

Verification

Fail-before (new test, run against the unpatched code):

Tests run: 4, Failures: 0, Errors: 1, Skipped: 1 -- NameServerAddressUtilsTest#testParseInstanceIdFromEndpointWithoutDot
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 29

Pass-after:

Tests run: 4, Failures: 0, Errors: 0, Skipped: 1 -- NameServerAddressUtilsTest

…romEndpoint

parseInstanceIdFromEndpoint used the result of endpoint.indexOf('.')
directly as the substring end index, so any non-empty endpoint without a
dot (for example "MQ_INST_123456789_BXXUzaee:80") produced -1 and threw
StringIndexOutOfBoundsException from a public utility. Treat a missing
dot as a non-instance endpoint and return null.
Copilot AI lite review requested due to automatic review settings September 11, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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.

Summary

Fix parseInstanceIdFromEndpoint to handle endpoints without a dot, returning null instead of throwing StringIndexOutOfBoundsException.

LGTM — clean defensive fix with test.


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.

3 participants