-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask1.java
More file actions
34 lines (27 loc) · 1.2 KB
/
Copy pathTask1.java
File metadata and controls
34 lines (27 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
class LoanAccountService {
public List<LoanAccount> getOverdueLoans(List<LoanAccount> accounts) {
// FIX: Initialize the result list so callers receive an empty list instead of null when no loans match.
List<LoanAccount> result = new ArrayList<>();
// FIX: Guard against null input to avoid NullPointerException in production support flows.
if (accounts == null) {
return result;
}
// FIX: Capture current date once so all accounts in this execution are compared against the same timestamp.
Date today = new Date();
for (LoanAccount account : accounts) {
// FIX: Skip null list entries defensively instead of failing the whole batch.
if (account == null) {
continue;
}
Date dueDate = account.getDueDate();
// FIX: dueDate may be null for restructured accounts; such accounts cannot be treated as overdue.
if (dueDate != null && dueDate.before(today) && account.getOutstandingBalance() > 0) {
result.add(account);
}
}
return result;
}
}