Skip to content

Commit 3eee799

Browse files
author
Zhang Wenhao
committed
<fix>[kvm]: fix NPE in VmHostFileTracker sync
When all getLastSyncDate() values in the stream are null, the min() operation with Comparator.nullsFirst() throws NPE because Optional.of() doesn't accept null. Filter null values before calling min() to avoid this issue. Resolves: ZSV-11779 Related: ZSV-11310 Change-Id: I646a65776a717465636e75616c70746763727862
1 parent 61d98c2 commit 3eee799

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

plugin/kvm/src/main/java/org/zstack/kvm/vmfiles/VmHostFileTracker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ private void syncVmHostFiles() {
269269
// check if force sync is needed based on lastSyncDate
270270
Timestamp oldestLastSync = group.stream()
271271
.map(VmHostFileVO::getLastSyncDate)
272-
.min(Comparator.nullsFirst(Comparator.naturalOrder()))
272+
.filter(Objects::nonNull)
273+
.min(Comparator.naturalOrder())
273274
.orElse(null);
274275

275276
if (oldestLastSync != null && (now - oldestLastSync.getTime()) < forceSyncThresholdMs) {

0 commit comments

Comments
 (0)