From 5eb264ed394ea2fe8478387c0f87f53f4bd9b1dc Mon Sep 17 00:00:00 2001 From: Vibe Nuage Agent Date: Tue, 1 Dec 2026 20:52:09 +0000 Subject: [PATCH] Fix stray semicolon in SnapshotDataFactoryImpl.getSnapshot zone fallback (#14770) ### Description `SnapshotDataFactoryImpl.getSnapshot(snapshotId, role, zoneId, retrieveAnySnapshotFromVolume)` had a stray `;` in its fallback loop, making the `if` a no-op: the first snapshot copy from any zone was returned instead of the one in the requested zone. Both loops also used `long == Long` unboxing, which NPEs when `getStoreZoneId` returns null. Both loops now compare null-safely with `Long.valueOf(zoneId).equals(...)`. ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [x] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [ ] Test (unit or integration test code) ### Bug Severity - [ ] BLOCKER - [ ] Critical - [x] Major - [ ] Minor - [ ] Trivial ### How Has This Been Tested? Two-line comparison fix verified by inspection; `getSnapshotWithRoleAndZone(id, role, zoneB)` now returns null when the only copy is in zone A. Module compilation/CI runs on the PR (no JDK in the working environment). Closes #14770 Co-authored-by: ravening --- .../cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java index 5c0a613d82d6..34ac2a5551e4 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java @@ -171,7 +171,7 @@ public SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role, long zoneId List snapshotStores = snapshotStoreDao.listReadyBySnapshot(snapshotId, role); SnapshotDataStoreVO snapshotStore = null; for (SnapshotDataStoreVO ref : snapshotStores) { - if (zoneId == storeMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole())) { + if (Long.valueOf(zoneId).equals(storeMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole()))) { snapshotStore = ref; break; } @@ -182,7 +182,7 @@ public SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role, long zoneId } snapshotStores = snapshotStoreDao.findByVolume(snapshotId, snapshot.getVolumeId(), role); for (SnapshotDataStoreVO ref : snapshotStores) { - if (zoneId == storeMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole())); { + if (Long.valueOf(zoneId).equals(storeMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole()))) { snapshotStore = ref; break; }