Source:
<code>public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate, Date endDate) { <START> if (quotaBalance.size() == 0) { <END> new InvalidParameterValueException("The request period does not contain balance entries."); } Collections.sort(quotaBalance, new Comparator<QuotaBalanceVO>() { public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { return o2.getUpdatedOn().compareTo(o1.getUpdatedOn()); } }); int quota_activity = quotaBalance.size(); QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); boolean consecutive = true; for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); s_logger.info("createQuotaBalanceResponse: Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); if (entry.getCreditsId() > 0) { if (consecutive) { lastCredits = lastCredits.add(entry.getCreditBalance()); } resp.addCredits(entry); it.remove(); } else { consecutive = false; } } if (quota_activity > 0 && quotaBalance.size() > 0) { QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1); QuotaBalanceVO endItem = quotaBalance.get(0); resp.setStartDate(startDate); resp.setStartQuota(startItem.getCreditBalance()); resp.setEndDate(endDate); resp.setEndQuota(endItem.getCreditBalance().add(lastCredits)); } else if (quota_activity > 0) { resp.setStartDate(startDate); resp.setStartQuota(new BigDecimal(0)); resp.setEndDate(endDate); resp.setEndQuota(new BigDecimal(0).add(lastCredits)); } else { resp.setStartQuota(new BigDecimal(0)); resp.setEndQuota(new BigDecimal(0)); } resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); resp.setObjectName("balance"); return resp; }</code><technical_language>In order avoid a NullPointerException, this if condition check quotaBalance is null. Also, consider com.google.common.base.Preconditions#checkArgument for checking validity of arguments</technical_language>

Target:
public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate, Date endDate) { if (quotaBalance == null || quotaBalance.size() == 0) { new InvalidParameterValueException("The request period does not contain balance entries."); } Collections.sort(quotaBalance, new Comparator<QuotaBalanceVO>() { public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { return o2.getUpdatedOn().compareTo(o1.getUpdatedOn()); } }); int quota_activity = quotaBalance.size(); QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); boolean consecutive = true; for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); if (s_logger.isDebugEnabled()){ s_logger.debug("createQuotaBalanceResponse: Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); } if (entry.getCreditsId() > 0) { if (consecutive) { lastCredits = lastCredits.add(entry.getCreditBalance()); } resp.addCredits(entry); it.remove(); } else { consecutive = false; } } if (quota_activity > 0 && quotaBalance.size() > 0) { QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1); QuotaBalanceVO endItem = quotaBalance.get(0); resp.setStartDate(startDate); resp.setStartQuota(startItem.getCreditBalance()); resp.setEndDate(endDate); resp.setEndQuota(endItem.getCreditBalance().add(lastCredits)); } else if (quota_activity > 0) { resp.setStartDate(startDate); resp.setStartQuota(new BigDecimal(0)); resp.setEndDate(endDate); resp.setEndQuota(new BigDecimal(0).add(lastCredits)); } else { resp.setStartQuota(new BigDecimal(0)); resp.setEndQuota(new BigDecimal(0)); } resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); resp.setObjectName("balance"); return resp; }