Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ public boolean deleteKubernetesCluster(DeleteKubernetesClusterCmd cmd) throws Cl

public static boolean checkIfVmsAssociatedWithBackupOffering(List<VMInstanceVO> vms) {
for(VMInstanceVO vm : vms) {
if (Objects.nonNull(vm.getBackupOfferingId())) {
if (ObjectUtils.allNotNull(vm, vm.getBackupOfferingId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will evaluation happen in the right order here? it seems to be the second argument will throw an NPE if applicable (i.e. vm is null) before the arguments are passed!?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the values are checked in the order.
if the first value is null, it returns false without checking the second value
I think it is same to vm != null && vm.getBackupOfferingId() != null

refer to the code of allNotNull method

    public static boolean allNotNull(Object... values) {
        if (values == null) {
            return false;
        } else {
            for(Object val : values) {
                if (val == null) {
                    return false;
                }
            }

            return true;
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running

    @Test
    public void testObjectsAreNull() {
        VMInstanceVO vm = null;
        ObjectUtils.allNotNull(vm, vm.getAccountId());
    }

will yield

java.lang.NullPointerException: Cannot invoke "com.cloud.vm.VMInstanceVO.getAccountId()" because "vm" is null

return true;
}
}
Expand Down
Loading