Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public static String parseInstanceIdFromEndpoint(String endpoint) {
if (StringUtils.isEmpty(endpoint)) {
return null;
}
return endpoint.substring(endpoint.lastIndexOf("/") + 1, endpoint.indexOf('.'));
int dotIndex = endpoint.indexOf('.');
if (dotIndex < 0) {
return null;
}
return endpoint.substring(endpoint.lastIndexOf("/") + 1, dotIndex);
}

public static String getNameSrvAddrFromNamesrvEndpoint(String nameSrvEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public void testParseInstanceIdFromEndpoint() {
"MQ_INST_123456789_BXXUzaee");
}

@Test
public void testParseInstanceIdFromEndpointWithoutDot() {
// an endpoint without a dot is not an instance endpoint; the utility must
// not throw StringIndexOutOfBoundsException on it
assertThat(NameServerAddressUtils.parseInstanceIdFromEndpoint("MQ_INST_123456789_BXXUzaee:80")).isNull();
assertThat(NameServerAddressUtils.parseInstanceIdFromEndpoint("localhost")).isNull();
}

@Test
public void testGetNameSrvAddrFromNamesrvEndpoint() {
assertThat(NameServerAddressUtils.getNameSrvAddrFromNamesrvEndpoint(endpoint1))
Expand Down