From 4e90cef79148719e8bcd3e8f265d22a59f9ea4f8 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 6 Mar 2026 13:54:39 +0100 Subject: [PATCH] Adding null checks to Share --- src/main/java/millions/Share.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/millions/Share.java b/src/main/java/millions/Share.java index afb3947..5db6738 100644 --- a/src/main/java/millions/Share.java +++ b/src/main/java/millions/Share.java @@ -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) {