From b2640b7f2cafaf2103ac54ab4d9494d15885b22d Mon Sep 17 00:00:00 2001 From: Thomas Cederholm Date: Mon, 18 May 2026 11:06:04 +0200 Subject: [PATCH] fix: Unbox Boolean pattern variable before ternary in SchemaParser Sonar java:S5411 flags using a boxed Boolean directly in a ternary as the implicit unboxing can NPE. Assign to a primitive local first so the intent is explicit and the rule passes. --- .../java/com/retailsvc/http/spec/schema/SchemaParser.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/retailsvc/http/spec/schema/SchemaParser.java b/src/main/java/com/retailsvc/http/spec/schema/SchemaParser.java index 7bfd905..3227a1f 100644 --- a/src/main/java/com/retailsvc/http/spec/schema/SchemaParser.java +++ b/src/main/java/com/retailsvc/http/spec/schema/SchemaParser.java @@ -24,7 +24,8 @@ static Map extractExtensions(Map raw) { public static Schema parse(Object raw) { if (raw instanceof Boolean b) { - return b ? new AlwaysSchema(Map.of()) : new NeverSchema(Map.of()); + boolean allow = b; + return allow ? new AlwaysSchema(Map.of()) : new NeverSchema(Map.of()); } if (raw instanceof Map map) { @SuppressWarnings("unchecked") @@ -208,7 +209,8 @@ private static ArraySchema parseArray(Map raw, Set typ if (itemsRaw == null) { itemSchema = new NullSchema(Map.of()); } else if (itemsRaw instanceof Boolean b) { - itemSchema = b ? new AlwaysSchema(Map.of()) : new NeverSchema(Map.of()); + boolean allow = b; + itemSchema = allow ? new AlwaysSchema(Map.of()) : new NeverSchema(Map.of()); } else { Map items = (Map) itemsRaw; itemSchema = items.isEmpty() ? new NullSchema(Map.of()) : parse(items);