Skip to content

Commit

Permalink
Adding null checks to Share
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 6, 2026
1 parent 13001ef commit 4e90cef
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/millions/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
this.stock = stock;
this.quantity = quantity;
this.purchasePrice = purchasePrice;

if (stock == null) {
throw new IllegalArgumentException("Stock cannot be null");
}
if (quantity == null) {
throw new IllegalArgumentException("Quantity cannot be null");
}
if (purchasePrice == null) {
throw new IllegalArgumentException("Purchase price cannot be null");
}
}

public Share(Stock stock, int quantity, BigDecimal purchasePrice) {
Expand Down

0 comments on commit 4e90cef

Please sign in to comment.