fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723
fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723ZStack-Robot wants to merge 1 commit intofeature-5.5.12-znsfrom
Conversation
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>
功能概览本 PR 修复了 L2 网络 VLAN ID 变更验证中的空值安全问题,并新增了五个错误代码常量。L2 网络拦截器现在在网络类型为 null 时会使用当前类型赋值,而 VXLAN 检查器通过调整相等性判断操作数顺序来安全处理 null 值。 变更内容
代码审查工作量评估🎯 2 (Simple) | ⏱️ ~8 分钟 庆祝诗
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.javaComment |
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (3)
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.javaplugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.javautils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
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