Skip to content

<fix>[network]: add null check for L3 network system tags in API interceptor#3340

Open
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/ZSTAC-81741
Open

<fix>[network]: add null check for L3 network system tags in API interceptor#3340
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/ZSTAC-81741

Conversation

@MatheMatrix
Copy link
Owner

Resolves: ZSTAC-81741\n\nFix NPE when L3 network system tags are null in L3NetworkApiInterceptor.

sync from gitlab !9169

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

概览

VmNicManagerImpl.java 中的 afterAddIpAddressafterDelIpAddress 方法增加了空值安全检查。当虚拟机网卡(VmNicVO)未被找到时,代码将记录调试信息并提前返回,以避免后续处理可能的空指针异常。

更改

内聚体 / 文件 摘要
虚拟机网卡管理器的空值安全性改进
compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.java
afterAddIpAddressafterDelIpAddress 方法中添加了 VmNicVO 获取后的空值检查。若网卡不存在,则输出调试日志并提前返回,防止潜在的空指针异常。

代码审查工作量评估

🎯 2 (简单) | ⏱️ ~10 分钟

小兔子提笔写代码,
空值检查守护心,
提前返回保安全,🐰
无指针异常来困扰,
代码更稳又更暖。


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 warnings)
Check name Status Explanation Resolution
Title check ❌ Error PR标题声称修复L3网络系统标签的空检查,但raw_summary显示实际改动是在VmNicManagerImpl中添加VmNicVO的空安全检查,两者不相关。 更新标题以准确反映实际改动:例如'[network]: add null check for VmNicVO in VmNicManager',或确保代码改动与标题声称的修复相符。
Description check ⚠️ Warning PR描述声称修复L3NetworkApiInterceptor中的NPE,但raw_summary和提交信息表明实际改动与UsedIpVO和VmNicVO有关,描述与实际改动不符。 更新描述以准确说明实际修改内容,确保与raw_summary中VmNicManagerImpl的改动一致。
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 (1 passed)
Check name Status Explanation
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into 5.5.6
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/ye.zou/fix/ZSTAC-81741

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

…fterAddIpAddress to prevent NPE during rollback

Resolves: ZSTAC-81741

Change-Id: I53bcf20a10306afc7b6172da294d347b74e6c41f
@MatheMatrix MatheMatrix force-pushed the sync/ye.zou/fix/ZSTAC-81741 branch from 540cd13 to f563992 Compare February 13, 2026 07:14
Copy link

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.java (1)

56-64: ⚠️ Potential issue | 🟠 Major

在确认 NIC 存在前先更新 UsedIpVO 可能造成数据不一致

如果 NIC 已被删除或不存在,这里会留下指向不存在 NIC 的 UsedIpVO 记录,后续可能导致 IP 无法正确回收或状态污染。建议先确认 NIC 存在,再更新 UsedIpVO。

✅ 建议调整更新顺序
-        /* update UsedIpVO */
-        SQL.New(UsedIpVO.class).eq(UsedIpVO_.uuid, usedIpUuid).set(UsedIpVO_.vmNicUuid, vmNicUUid).update();
-
-        VmNicVO nic = Q.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid).find();
-        if (nic == null) {
-            logger.debug(String.format("VmNic[uuid:%s] not found, skip afterAddIpAddress", vmNicUUid));
-            return;
-        }
+        VmNicVO nic = Q.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid).find();
+        if (nic == null) {
+            logger.debug(String.format("VmNic[uuid:%s] not found, skip afterAddIpAddress", vmNicUUid));
+            return;
+        }
+
+        /* update UsedIpVO */
+        SQL.New(UsedIpVO.class).eq(UsedIpVO_.uuid, usedIpUuid).set(UsedIpVO_.vmNicUuid, vmNicUUid).update();

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