From caf524dab2eeb02dcc259f22c21a1febcd099c61 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 28 Nov 2024 23:34:44 +0100 Subject: [PATCH] java: require all GherkinDialect properties to be non-null (#329) While the code generation and package private constructor already ensure that all fields are non-null, it is good to have this explicitly enforced in the code. --- .../io/cucumber/gherkin/GherkinDialect.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/java/src/main/java/io/cucumber/gherkin/GherkinDialect.java b/java/src/main/java/io/cucumber/gherkin/GherkinDialect.java index bfe01e0d5..6fa7f16e7 100644 --- a/java/src/main/java/io/cucumber/gherkin/GherkinDialect.java +++ b/java/src/main/java/io/cucumber/gherkin/GherkinDialect.java @@ -6,8 +6,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import static java.util.Collections.unmodifiableList; +import static java.util.Objects.requireNonNull; public final class GherkinDialect { private final String language; @@ -28,20 +30,20 @@ public final class GherkinDialect { private final Map> stepKeywordsTypes; GherkinDialect(String language, String name, String nativeName, List featureKeywords, List ruleKeywords, List scenarioKeywords, List scenarioOutlineKeywords, List backgroundKeywords, List examplesKeywords, List givenKeywords, List whenKeywords, List thenKeywords, List andKeywords, List butKeywords) { - this.language = language; - this.name = name; - this.nativeName = nativeName; - this.featureKeywords = featureKeywords; - this.ruleKeywords = ruleKeywords; - this.scenarioKeywords = scenarioKeywords; - this.scenarioOutlineKeywords = scenarioOutlineKeywords; - this.backgroundKeywords = backgroundKeywords; - this.examplesKeywords = examplesKeywords; - this.givenKeywords = givenKeywords; - this.whenKeywords = whenKeywords; - this.thenKeywords = thenKeywords; - this.andKeywords = andKeywords; - this.butKeywords = butKeywords; + this.language = requireNonNull(language); + this.name = requireNonNull(name); + this.nativeName = requireNonNull(nativeName); + this.featureKeywords = requireNonNull(featureKeywords); + this.ruleKeywords = requireNonNull(ruleKeywords); + this.scenarioKeywords = requireNonNull(scenarioKeywords); + this.scenarioOutlineKeywords = requireNonNull(scenarioOutlineKeywords); + this.backgroundKeywords = requireNonNull(backgroundKeywords); + this.examplesKeywords = requireNonNull(examplesKeywords); + this.givenKeywords = requireNonNull(givenKeywords); + this.whenKeywords = requireNonNull(whenKeywords); + this.thenKeywords = requireNonNull(thenKeywords); + this.andKeywords = requireNonNull(andKeywords); + this.butKeywords = requireNonNull(butKeywords); List stepKeywords = new ArrayList<>(); stepKeywords.addAll(givenKeywords);