From eea0cf2b9822ec3330fa5c67d1fcf8cf0507b9a6 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 6 Mar 2026 13:54:59 +0100 Subject: [PATCH] Adding null and blank checks to Stock --- src/main/java/millions/Stock.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/millions/Stock.java b/src/main/java/millions/Stock.java index 41a3ead..632c4b7 100644 --- a/src/main/java/millions/Stock.java +++ b/src/main/java/millions/Stock.java @@ -13,12 +13,18 @@ public Stock(String symbol, String company, List prices) { this.symbol = symbol; this.company = company; this.prices = new ArrayList<>(prices); + + if (symbol == null || symbol.isBlank()) { + throw new IllegalArgumentException("Symbol cannot be null or blank"); + } + + if (company == null || company.isBlank()) { + throw new IllegalArgumentException("Company cannot be null or blank"); + } } public Stock(String symbol, String company, BigDecimal initialPrice) { - this.symbol = symbol; - this.company = company; - this.prices = new ArrayList<>(List.of(initialPrice)); + this(symbol, company, new ArrayList<>(List.of(initialPrice))); } public String getSymbol() {