CLOUDSTACK-4736 Fixed issue in default service selection
Fix CID 1127027 Dereference before null check

template can't be null at this point as it has already been dereferenced
Fix CID 1127021 Operands don't affect results

int can never be bigger than maxint.

Auto unboxing of Integer, not need for intValue()