Source:
<code>protected void compensate() { try { if (this instanceof Quotable) { ((Quotable) this).rollbackQuota(); } <START> } catch (Exception e) { <END> log.debug("RollbackQuota: failed (may be because quota is disabled)", e); } TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() { @Override public Object runInTransaction() { Deserializer deserializer = SerializationFactory.getFactory().createDeserializer(); List<BusinessEntitySnapshot> entitySnapshots = getBusinessEntitySnapshotDAO().getAllForCommandId(commandId); log.debugFormat("Command [id={0}]: {1} compensation data.", commandId, entitySnapshots.isEmpty() ? "No" : "Going over"); for (BusinessEntitySnapshot snapshot : entitySnapshots) { Class<Serializable> snapshotClass = (Class<Serializable>) ReflectionUtils.getClassFor(snapshot.getSnapshotClass()); Serializable snapshotData = deserializer.deserialize(snapshot.getEntitySnapshot(), snapshotClass); log.infoFormat("Command [id={0}]: Compensating {1} of {2}; snapshot: {3}.", commandId, snapshot.getSnapshotType(), snapshot.getEntityType(), (snapshot.getSnapshotType() == SnapshotType.CHANGED_ENTITY ? "id=" + snapshot.getEntityId() : snapshotData.toString())); Class<BusinessEntity<Serializable>> entityClass = (Class<BusinessEntity<Serializable>>) ReflectionUtils.getClassFor(snapshot.getEntityType()); GenericDao<BusinessEntity<Serializable>, Serializable> daoForEntity = DbFacade.getInstance().getDaoForEntity(entityClass); switch (snapshot.getSnapshotType()) { case CHANGED_STATUS_ONLY: EntityStatusSnapshot entityStatusSnapshot = (EntityStatusSnapshot) snapshotData; ((StatusAwareDao<Serializable, Enum<?>>) daoForEntity).updateStatus( entityStatusSnapshot.getId(), entityStatusSnapshot.getStatus()); break; case CHANGED_ENTITY: BusinessEntity<Serializable> entitySnapshot = (BusinessEntity<Serializable>) snapshotData; if (daoForEntity.get(entitySnapshot.getId()) == null) { daoForEntity.save(entitySnapshot); } else { daoForEntity.update(entitySnapshot); } break; case NEW_ENTITY_ID: daoForEntity.remove(snapshotData); break; } } cleanUpCompensationData(); return null; } }); }</code><technical_language>Please catch NPE. If else that</technical_language>

Target:
protected void compensate() { try { if (this instanceof Quotable) { ((Quotable) this).rollbackQuota(); } } catch (NullPointerException e) { log.debug("RollbackQuota: failed (may be because quota is disabled)", e); } TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() { @Override public Object runInTransaction() { Deserializer deserializer = SerializationFactory.getFactory().createDeserializer(); List<BusinessEntitySnapshot> entitySnapshots = getBusinessEntitySnapshotDAO().getAllForCommandId(commandId); log.debugFormat("Command [id={0}]: {1} compensation data.", commandId, entitySnapshots.isEmpty() ? "No" : "Going over"); for (BusinessEntitySnapshot snapshot : entitySnapshots) { Class<Serializable> snapshotClass = (Class<Serializable>) ReflectionUtils.getClassFor(snapshot.getSnapshotClass()); Serializable snapshotData = deserializer.deserialize(snapshot.getEntitySnapshot(), snapshotClass); log.infoFormat("Command [id={0}]: Compensating {1} of {2}; snapshot: {3}.", commandId, snapshot.getSnapshotType(), snapshot.getEntityType(), (snapshot.getSnapshotType() == SnapshotType.CHANGED_ENTITY ? "id=" + snapshot.getEntityId() : snapshotData.toString())); Class<BusinessEntity<Serializable>> entityClass = (Class<BusinessEntity<Serializable>>) ReflectionUtils.getClassFor(snapshot.getEntityType()); GenericDao<BusinessEntity<Serializable>, Serializable> daoForEntity = DbFacade.getInstance().getDaoForEntity(entityClass); switch (snapshot.getSnapshotType()) { case CHANGED_STATUS_ONLY: EntityStatusSnapshot entityStatusSnapshot = (EntityStatusSnapshot) snapshotData; ((StatusAwareDao<Serializable, Enum<?>>) daoForEntity).updateStatus( entityStatusSnapshot.getId(), entityStatusSnapshot.getStatus()); break; case CHANGED_ENTITY: BusinessEntity<Serializable> entitySnapshot = (BusinessEntity<Serializable>) snapshotData; if (daoForEntity.get(entitySnapshot.getId()) == null) { daoForEntity.save(entitySnapshot); } else { daoForEntity.update(entitySnapshot); } break; case NEW_ENTITY_ID: daoForEntity.remove(snapshotData); break; } } cleanUpCompensationData(); return null; } }); }