You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "wjwang00 (via GitHub)" <gi...@apache.org> on 2025/04/12 08:46:49 UTC
[PR] bugfix: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
wjwang00 opened a new pull request, #7282:
URL: https://github.com/apache/incubator-seata/pull/7282
…ileRegistryServiceImpl class.
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing guidelines -->
- [ ] I have registered the PR [changes](../changes).
### Ⅰ. Describe what this PR did
prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class
Due to the design characteristics of `NetUtil.splitIPPortStr(endpoint)`:
- If the `endpoint` does not contain a ":", it returns `null`.
- If the `endpoint` contains a ":", it returns an array of fixed length 2 (even if the content is empty, e.g., `":"` → `["", ""]`).
As a result:
1. The condition `if (ipAndPort.length != 2)` will **never be triggered**.
2. A `NullPointerException` will be thrown when the `endpoint` does not contain a ":".
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
### Ⅲ. Why don't you add test cases (unit test/integration test)?
just fix bug
### Ⅳ. Describe how to verify it
### Ⅴ. Special notes for reviews
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#issuecomment-2813116776
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `66.66667%` with `2 lines` in your changes missing coverage. Please review.
> Project coverage is 54.22%. Comparing base [(`13d2db4`)](https://app.codecov.io/gh/apache/incubator-seata/commit/13d2db49354f1f25d58267e6c83603e41e8adcbb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`81a35ae`)](https://app.codecov.io/gh/apache/incubator-seata/commit/81a35ae726ee41b6ea32c6e34661b2b27f345e65?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ain/java/org/apache/seata/common/util/NetUtil.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Futil%2FNetUtil.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vdXRpbC9OZXRVdGlsLmphdmE=) | 66.66% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 2.x #7282 +/- ##
============================================
- Coverage 54.22% 54.22% -0.01%
Complexity 7266 7266
============================================
Files 1178 1178
Lines 41961 41959 -2
Branches 4923 4923
============================================
- Hits 22754 22752 -2
+ Misses 17056 17054 -2
- Partials 2151 2153 +2
```
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...ta/discovery/registry/FileRegistryServiceImpl.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?src=pr&el=tree&filepath=discovery%2Fseata-discovery-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fdiscovery%2Fregistry%2FFileRegistryServiceImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGlzY292ZXJ5L3NlYXRhLWRpc2NvdmVyeS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9kaXNjb3ZlcnkvcmVnaXN0cnkvRmlsZVJlZ2lzdHJ5U2VydmljZUltcGwuamF2YQ==) | `0.00% <ø> (ø)` | |
| [...ain/java/org/apache/seata/common/util/NetUtil.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Futil%2FNetUtil.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vdXRpbC9OZXRVdGlsLmphdmE=) | `45.27% <66.66%> (-2.71%)` | :arrow_down: |
... and [3 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/7282/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
[](https://app.codecov.io/gh/apache/incubator-seata/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly commented on code in PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#discussion_r2055140962
##########
common/src/main/java/org/apache/seata/common/util/NetUtil.java:
##########
@@ -138,18 +138,20 @@ public static String[] splitIPPortStr(String address) {
if (address.charAt(0) == '[') {
address = removeBrackets(address);
}
- String[] serverAddArr = null;
int i = address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR);
if (i > -1) {
- serverAddArr = new String[2];
- String hostAddress = address.substring(0,i);
+ String hostAddress = address.substring(0, i);
if (hostAddress.contains("%")) {
hostAddress = hostAddress.substring(0, hostAddress.indexOf("%"));
}
- serverAddArr[0] = hostAddress;
- serverAddArr[1] = address.substring(i + 1);
+ String portStr = address.substring(i + 1);
+ if (StringUtils.isBlank(hostAddress) || StringUtils.isBlank(portStr)) {
+ throw new IllegalArgumentException("Invalid endpoint format: " + address + ". Endpoint should be in the format ip:port.");
Review Comment:
Pls. add UT case for this exception.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly merged PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly commented on code in PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#discussion_r2055141388
##########
common/src/main/java/org/apache/seata/common/util/NetUtil.java:
##########
@@ -138,18 +138,20 @@ public static String[] splitIPPortStr(String address) {
if (address.charAt(0) == '[') {
address = removeBrackets(address);
}
- String[] serverAddArr = null;
int i = address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR);
if (i > -1) {
- serverAddArr = new String[2];
- String hostAddress = address.substring(0,i);
+ String hostAddress = address.substring(0, i);
if (hostAddress.contains("%")) {
hostAddress = hostAddress.substring(0, hostAddress.indexOf("%"));
}
- serverAddArr[0] = hostAddress;
- serverAddArr[1] = address.substring(i + 1);
+ String portStr = address.substring(i + 1);
+ if (StringUtils.isBlank(hostAddress) || StringUtils.isBlank(portStr)) {
+ throw new IllegalArgumentException("Invalid endpoint format: " + address + ". Endpoint should be in the format ip:port.");
+ }
+ return new String[]{hostAddress, portStr};
Review Comment:
It is best to verify the numeric type of the port and the range of the port.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "wjwang00 (via GitHub)" <gi...@apache.org>.
wjwang00 commented on code in PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#discussion_r2055879920
##########
common/src/main/java/org/apache/seata/common/util/NetUtil.java:
##########
@@ -138,18 +138,20 @@ public static String[] splitIPPortStr(String address) {
if (address.charAt(0) == '[') {
address = removeBrackets(address);
}
- String[] serverAddArr = null;
int i = address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR);
if (i > -1) {
- serverAddArr = new String[2];
- String hostAddress = address.substring(0,i);
+ String hostAddress = address.substring(0, i);
if (hostAddress.contains("%")) {
hostAddress = hostAddress.substring(0, hostAddress.indexOf("%"));
}
- serverAddArr[0] = hostAddress;
- serverAddArr[1] = address.substring(i + 1);
+ String portStr = address.substring(i + 1);
+ if (StringUtils.isBlank(hostAddress) || StringUtils.isBlank(portStr)) {
+ throw new IllegalArgumentException("Invalid endpoint format: " + address + ". Endpoint should be in the format ip:port.");
+ }
+ return new String[]{hostAddress, portStr};
Review Comment:
OK, I have verified the numeric type of the port and the range of the port, and I have also added some test cases to cover the new code. Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "wjwang00 (via GitHub)" <gi...@apache.org>.
wjwang00 commented on code in PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#discussion_r2040659631
##########
discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/FileRegistryServiceImpl.java:
##########
@@ -89,7 +89,7 @@ public List<InetSocketAddress> lookup(String key) throws Exception {
List<InetSocketAddress> inetSocketAddresses = new ArrayList<>();
for (String endpoint : endpoints) {
String[] ipAndPort = NetUtil.splitIPPortStr(endpoint);
- if (ipAndPort.length != 2) {
+ if (ipAndPort == null || ipAndPort[0].isEmpty() || ipAndPort[1].isEmpty() ) {
Review Comment:
Sure, I have adjusted the `NetUtil.splitIPPortStr` method to ensure that the returned result is definitely a string array of length 2 with the correct format. The caller no longer needs to validate the returned result.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] optimize: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "wjwang00 (via GitHub)" <gi...@apache.org>.
wjwang00 commented on PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#issuecomment-2806797311
> You need to adjust the UT of NetUtilTest to make it as expected.
>
> https://github.com/apache/incubator-seata/actions/runs/14420166446/job/40441706978?pr=7282
>
> https://github.com/apache/incubator-seata/blob/2.x/common/src/test/java/org/apache/seata/common/util/NetUtilTest.java
ok,I appreciate your reminder.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: prevent unexpected NullPointerException in lookup method in FileRegistryServiceImpl class [incubator-seata]
Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly commented on code in PR #7282:
URL: https://github.com/apache/incubator-seata/pull/7282#discussion_r2040645694
##########
discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/FileRegistryServiceImpl.java:
##########
@@ -89,7 +89,7 @@ public List<InetSocketAddress> lookup(String key) throws Exception {
List<InetSocketAddress> inetSocketAddresses = new ArrayList<>();
for (String endpoint : endpoints) {
String[] ipAndPort = NetUtil.splitIPPortStr(endpoint);
- if (ipAndPort.length != 2) {
+ if (ipAndPort == null || ipAndPort[0].isEmpty() || ipAndPort[1].isEmpty() ) {
Review Comment:
It is suggested that the judgments of ipAndPort[0] and ipAndPort[1] converge to the NetUtil.splitIPPortStr method. It is necessary to determine whether the outer caller ipAndPort is null and its length (there is a reference to the array below).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org