From ed63b143c8421ec700c57accff8dcce2a80e0e59 Mon Sep 17 00:00:00 2001 From: Tomasz Nguyen Date: Wed, 16 Feb 2022 12:52:46 +0000 Subject: [PATCH] fix: pass DCN_NULLPOINTER_EXCEPTION spotbugs error We have changed our SpotBugs version to 4.5.3 which was causing: ``` [ERROR] Medium: Do not catch NullPointerException like in io.confluent.ksql.datagen.DataGen$Arguments$Builder.build() [io.confluent.ksql.datagen.DataGen$Arguments$Builder] At DataGen.java:[line 440] DCN_NULLPOINTER_EXCEPTION [INFO] ``` This change is SpotBugs compliant way of doing the same thing - explicit null checks, rather than delegating to a method that checks for null and throws NPE --- .../io/confluent/ksql/datagen/DataGen.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ksqldb-examples/src/main/java/io/confluent/ksql/datagen/DataGen.java b/ksqldb-examples/src/main/java/io/confluent/ksql/datagen/DataGen.java index 0936c8f9f250..d9a47ec7d86b 100644 --- a/ksqldb-examples/src/main/java/io/confluent/ksql/datagen/DataGen.java +++ b/ksqldb-examples/src/main/java/io/confluent/ksql/datagen/DataGen.java @@ -29,7 +29,6 @@ import java.io.InputStream; import java.util.Arrays; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Properties; import java.util.Random; @@ -364,14 +363,20 @@ Arguments build() { timestampColumnName = Optional.ofNullable(timestampColumnName).orElse(null); } - try { - Objects.requireNonNull(schemaFile, "Schema file not provided"); - Objects.requireNonNull(keyFormat, "Message key format not provided"); - Objects.requireNonNull(valueFormat, "Message value format not provided"); - Objects.requireNonNull(topicName, "Kafka topic name not provided"); - Objects.requireNonNull(keyName, "Name of key column not provided"); - } catch (final NullPointerException exception) { - throw new ArgumentParseException(exception.getMessage()); + if (schemaFile == null) { + throw new ArgumentParseException("Schema file not provided"); + } + if (keyFormat == null) { + throw new ArgumentParseException("Message key format not provided"); + } + if (valueFormat == null) { + throw new ArgumentParseException("Message value format not provided"); + } + if (topicName == null) { + throw new ArgumentParseException("Kafka topic name not provided"); + } + if (keyName == null) { + throw new ArgumentParseException("Name of key column not provided"); } return new Arguments( help,