mirror of https://github.com/apache/cloudstack.git
findbugs: check for system template id == -> equals()
This commit is contained in:
parent
0d7a96526c
commit
15fa2ef8df
|
|
@ -1753,12 +1753,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
throw ex;
|
||||
}
|
||||
|
||||
// Don't allow to modify system template
|
||||
if (id == Long.valueOf(1)) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
|
||||
ex.addProxyObject(String.valueOf(id), "templateId");
|
||||
throw ex;
|
||||
}
|
||||
verifyTemplateId(id);
|
||||
|
||||
// do a permission check
|
||||
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
|
||||
|
|
@ -1835,6 +1830,15 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
return _tmpltDao.findById(id);
|
||||
}
|
||||
|
||||
void verifyTemplateId(Long id) {
|
||||
// Don't allow to modify system template
|
||||
if (id.equals(Long.valueOf(1))) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
|
||||
ex.addProxyObject(String.valueOf(id), "templateId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigComponentName() {
|
||||
return TemplateManager.class.getSimpleName();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.cloud.template;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
public class TemplateManagerImplTest {
|
||||
|
||||
TemplateManagerImpl tmgr = new TemplateManagerImpl();
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void testVerifyTemplateIdOfSystemTemplate() {
|
||||
tmgr.verifyTemplateId(1L);
|
||||
}
|
||||
|
||||
public void testVerifyTemplateIdOfNonSystemTemplate() {
|
||||
tmgr.verifyTemplateId(1L);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue