Commit 98ec46c
Guard null host in releaseVmCapacity and reuse resolved lastHost
Two defensive fixes from Copilot's review of PR #13363:
1. releaseVmCapacity(VM, ..., Long hostId): _hostDao.findById(hostId)
can return null when last_host_id points to a deleted host. The
subsequent host.getHypervisorType() check would NPE. The Host
overload already null-checks AND has the External check, so
delegate to it instead of duplicating the External check here.
2. postStateTransitionEvent: the lastHost was being fetched twice
(once for logging at L942, again inside releaseVmCapacity via
the Long overload at L987). Reuse the already-resolved Host. The
Host overload also handles null, so the explicit null check on
getLastHostId() becomes redundant.
(Skipped Copilot's third suggestion to guard findById(null) — the
GenericDaoBase.findById(ID, boolean, Boolean) implementation at
GenericDaoBase.java:1066 explicitly returns null for null id, so
the existing code is already safe.)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6f09730 commit 98ec46c
2 files changed
Lines changed: 10 additions & 11 deletions
File tree
- server/src
- main/java/com/cloud/capacity
- test/java/com/cloud/capacity
Lines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 175 | | |
179 | 176 | | |
180 | 177 | | |
| |||
983 | 980 | | |
984 | 981 | | |
985 | 982 | | |
986 | | - | |
987 | | - | |
988 | | - | |
| 983 | + | |
989 | 984 | | |
990 | 985 | | |
991 | 986 | | |
| |||
Lines changed: 9 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
177 | 179 | | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
184 | | - | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
192 | | - | |
| 194 | + | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
206 | | - | |
| 210 | + | |
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
212 | 216 | | |
213 | 217 | | |
214 | | - | |
| 218 | + | |
215 | 219 | | |
216 | 220 | | |
217 | 221 | | |
| |||
0 commit comments