atrocitytheme opened a new pull request #5358:
URL: https://github.com/apache/cloudstack/pull/5358
### Description
The recent changes of the main branch enable the global setting to select
preferred storage pool and apply its implementation in the
VolumeOrchestrator.java in the findStoragePool method
```
Optional<StoragePool> storagePool = getPreferredStoragePool(poolList, vm);
```
But the usage of it has a potential risk of null pointer exception when the
vm parameter in findStoragePool is null, current implementation of
getPreferredStoragePool doesn't handle such a condition and directly assumes
that VM is never null.
```
String accountStoragePoolUuid =
StorageManager.PreferredStoragePool.valueIn(vm.getAccountId());
```
But in one of the implementations in the same class where the
findStoragePool is called, it passes vm variable explicitly as null
*interface*
```
public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot,
UserVm vm) throws StorageUnavailableException;
```
When the VM is creating a volume from a snapshot whose VM or pod is not
specified, a null pointer exception might happen due to this null passing of
the "VM" variable around line 467 in the VolumeOrchestrator.java
```
while ((pool = findStoragePool(dskCh, dc, pod.first(), null, null, null,
poolsToAvoid)) != null) {
break;
}
```
This PR adds a null handler and returns the default pool when the vm is null
### 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)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [x] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [x] Minor
- [ ] Trivial
### Screenshots (if appropriate):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]