Skip to content

Commit 6b25ed7

Browse files
authored
prevent an NPE on an uninitialised TemplateObject (#8898)
* prevent an NPE on an uninitialised TemplateObject * move npe handler up-stack * Update engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java * catch yet one level up * Update engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java * Update engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java * extra guard * Revert "prevent an NPE on an uninitialised TemplateObject" This reverts commit e602a65.
1 parent 351de5f commit 6b25ed7

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public TemplateInfo getTemplate(long templateId) {
9999
@Override
100100
public TemplateInfo getTemplate(long templateId, DataStore store) {
101101
VMTemplateVO templ = imageDataDao.findById(templateId);
102+
if (templ == null) {
103+
return null;
104+
}
102105
if (store == null && !templ.isDirectDownload()) {
103106
TemplateObject tmpl = TemplateObject.getTemplate(templ, null, null);
104107
return tmpl;

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public TemplateObject() {
8181
}
8282

8383
protected void configure(VMTemplateVO template, DataStore dataStore) {
84+
if (template == null) {
85+
String msg = String.format("Template Object is not properly initialised %s", this.toString());
86+
s_logger.warn(msg);
87+
}
8488
imageVO = template;
8589
this.dataStore = dataStore;
8690
}
@@ -97,6 +101,10 @@ public void setSize(Long size) {
97101
}
98102

99103
public VMTemplateVO getImage() {
104+
if (imageVO == null) {
105+
String msg = String.format("Template Object is not properly initialised %s", this.toString());
106+
s_logger.error(msg);
107+
} // somehow the nullpointer is needed : refacter needed!?!
100108
return imageVO;
101109
}
102110

0 commit comments

Comments
 (0)