Skip to content

Detect ip:port with contains in NetUtils.matchIpExpression#16358

Open
vasiliy-mikhailov wants to merge 1 commit into
apache:3.3from
vasiliy-mikhailov:fix/netutils-matchip-contains-colon
Open

Detect ip:port with contains in NetUtils.matchIpExpression#16358
vasiliy-mikhailov wants to merge 1 commit into
apache:3.3from
vasiliy-mikhailov:fix/netutils-matchip-contains-colon

Conversation

@vasiliy-mikhailov

@vasiliy-mikhailov vasiliy-mikhailov commented Jun 27, 2026

Copy link
Copy Markdown

The deprecated two-arg matchIpExpression(pattern, address) uses address.endsWith(":") to detect the ip:port format. A real address such as 192.168.1.63:90 ends with the port, not a colon, so the host/port split is skipped — the full host:port string is then used as the host and matching fails. Use contains(":") to detect the separator.

Added a test covering ip:port addresses against patterns with and without a port.

Verifying this change

The added NetUtilsTest#testMatchIpExpressionDeprecatedTwoArgsWithIpPort fails before this change and passes after:

Before the fix:

$ mvn test -Dtest=NetUtilsTest -pl dubbo-common
[INFO] Running org.apache.dubbo.common.utils.NetUtilsTest
[ERROR] Tests run: 49, Failures: 0, Errors: 1, Skipped: 2 <<< ERROR!
java.net.UnknownHostException: 192.168.1.63:90: invalid IPv6 address literal
	at org.apache.dubbo.common.utils.NetUtils.matchIpRange(NetUtils.java:784)
	at org.apache.dubbo.common.utils.NetUtils.matchIpExpression(NetUtils.java:753)
	at org.apache.dubbo.common.utils.NetUtilsTest.testMatchIpExpressionDeprecatedTwoArgsWithIpPort(NetUtilsTest.java:357)
[INFO] BUILD FAILURE

After the fix:

$ mvn test -Dtest=NetUtilsTest -pl dubbo-common
[INFO] Running org.apache.dubbo.common.utils.NetUtilsTest
[INFO] Tests run: 49, Failures: 0, Errors: 0, Skipped: 2
[INFO] BUILD SUCCESS

AI assistance disclosure

This contribution was produced with the help of an AI pipeline. The pipeline processed a large amount of source code to surface suspected bugs, reproduced a subset of them with failing unit tests and generated candidate fixes, and prepared pull requests from the ones that held up. Each PR was then reviewed and verified by a human before being opened: the fix and test were checked by hand and the test was confirmed to fail before the change and pass after.

The deprecated two-arg matchIpExpression used address.endsWith(":") to detect the ip:port format, but a real address like 192.168.1.63:90 ends with the port, not a colon, so the host/port split was skipped and matching failed. Use contains(":") to detect the separator.
@codecov-commenter

codecov-commenter commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.76%. Comparing base (866860d) to head (35ad362).
⚠️ Report is 4 commits behind head on 3.3.

Files with missing lines Patch % Lines
...n/java/org/apache/dubbo/common/utils/NetUtils.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16358      +/-   ##
============================================
- Coverage     60.80%   60.76%   -0.04%     
- Complexity       15    11766   +11751     
============================================
  Files          1953     1953              
  Lines         89208    89197      -11     
  Branches      13458    13375      -83     
============================================
- Hits          54245    54205      -40     
+ Misses        29397    29376      -21     
- Partials       5566     5616      +50     
Flag Coverage Δ
integration-tests-java21 32.10% <0.00%> (+<0.01%) ⬆️
integration-tests-java8 32.23% <0.00%> (-0.07%) ⬇️
samples-tests-java21 32.18% <0.00%> (+<0.01%) ⬆️
samples-tests-java8 29.82% <0.00%> (+0.10%) ⬆️
unit-tests-java11 59.07% <0.00%> (+0.04%) ⬆️
unit-tests-java17 58.56% <0.00%> (+0.03%) ⬆️
unit-tests-java21 58.55% <0.00%> (+0.05%) ⬆️
unit-tests-java25 58.54% <0.00%> (+0.09%) ⬆️
unit-tests-java8 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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