Skip to content

fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723

Open
ZStack-Robot wants to merge 1 commit intofeature-5.5.12-znsfrom
sync/shixin.ruan/shixin.ruan-zcf-2074@@2
Open

fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723
ZStack-Robot wants to merge 1 commit intofeature-5.5.12-znsfrom
sync/shixin.ruan/shixin.ruan-zcf-2074@@2

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

When type param is null in APIChangeL2NetworkVlanIdMsg, default to current
network type to prevent NPE in interceptors and handlers. Add null-safe
type check in VxlanNetworkCheckerImpl. Add ZNS error codes 10011-10015.

Resolves: ZCF-2074

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

sync from gitlab !9593

When type param is null in APIChangeL2NetworkVlanIdMsg, default to current
network type to prevent NPE in interceptors and handlers. Add null-safe
type check in VxlanNetworkCheckerImpl. Add ZNS error codes 10011-10015.

Resolves: ZCF-2074

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

功能概览

本 PR 修复了 L2 网络 VLAN ID 变更验证中的空值安全问题,并新增了五个错误代码常量。L2 网络拦截器现在在网络类型为 null 时会使用当前类型赋值,而 VXLAN 检查器通过调整相等性判断操作数顺序来安全处理 null 值。

变更内容

内聚体 / 文件 摘要
空值安全修复
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java, plugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.java
修复 VLAN ID 变更验证中的空值处理问题。L2 网络拦截器在消息类型为 null 时,使用 L2 网络的现有类型进行赋值;VXLAN 检查器通过反转相等性判断的操作数顺序,避免在 msg.getType() 为 null 时抛出 NullPointerException。
错误代码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
新增五个公共错误代码常量:ORG_ZSTACK_NETWORK_ZNS_10011ORG_ZSTACK_NETWORK_ZNS_10015

代码审查工作量评估

🎯 2 (Simple) | ⏱️ ~8 分钟

庆祝诗

🐰 空值已驱,验证更稳,
常数新增五,错码有迹寻,
代码如兔跃,安全无虞困!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows the required format '[scope]: ' and is 60 characters, well under the 72 character limit. The title accurately describes the main change of supporting ChangeL2NetworkVlanId for ZNS networks.
Description check ✅ Passed The pull request description is directly related to the changeset, explaining the null-type handling in APIChangeL2NetworkVlanIdMsg, the null-safe check in VxlanNetworkCheckerImpl, and the addition of ZNS error codes, all of which match the file changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/shixin.ruan/shixin.ruan-zcf-2074@@2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.1)
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java (1)

147-150: 建议在默认回填前对 type 做 trim 归一化

Line 147-150 目前只处理 null。若传入空白字符串(如 " "),不会回填默认类型,可能绕过后续类型分支校验。建议在这里先 trimToNull 再回填。

建议修改
-        // When type is not specified, default to the current network type
-        if (msg.getType() == null) {
-            msg.setType(l2.getType());
-        }
+        // When type is not specified, default to the current network type
+        msg.setType(StringUtils.trimToNull(msg.getType()));
+        if (msg.getType() == null) {
+            msg.setType(l2.getType());
+        }

As per coding guidelines "注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等"。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java`
around lines 147 - 150, The code in L2NetworkApiInterceptor currently only
checks msg.getType() for null before filling the default; update the logic to
normalize/trim the incoming type first (e.g., treat blank or whitespace-only
strings as null) by using a trim-to-null step on msg.getType() and then call
msg.setType(l2.getType()) when the trimmed value is null/empty; locate the
handling around msg.getType()/msg.setType() in L2NetworkApiInterceptor and apply
the trim-to-null normalization prior to the default-backfill so blank strings
don't bypass type validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java`:
- Around line 147-150: The code in L2NetworkApiInterceptor currently only checks
msg.getType() for null before filling the default; update the logic to
normalize/trim the incoming type first (e.g., treat blank or whitespace-only
strings as null) by using a trim-to-null step on msg.getType() and then call
msg.setType(l2.getType()) when the trimmed value is null/empty; locate the
handling around msg.getType()/msg.setType() in L2NetworkApiInterceptor and apply
the trim-to-null normalization prior to the default-backfill so blank strings
don't bypass type validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 9dfccf31-b657-456c-9192-2285114fdae7

📥 Commits

Reviewing files that changed from the base of the PR and between 17d06ab and 9ad4368.

📒 Files selected for processing (3)
  • network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java
  • plugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.java
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

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