From 644a860d3f61e15c7eb59eaa1ed18a85d5644974 Mon Sep 17 00:00:00 2001 From: Pratik Mallya Date: Wed, 7 Oct 2020 20:56:36 -0700 Subject: [PATCH] Don't NPE when config option is not specified When some of the options are incorrectly specified, jack will throw an NPE when trying to craft a user-friendly error message. You can see this in the current version by not specifying the `adaptor` parameter. This change attempts to avoid such an error by not failing when crafting an exception error message. --- .../com/rapleaf/jack/DatabaseConnectionConfiguration.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jack-core/src/com/rapleaf/jack/DatabaseConnectionConfiguration.java b/jack-core/src/com/rapleaf/jack/DatabaseConnectionConfiguration.java index f2c6fc0e..a020923d 100644 --- a/jack-core/src/com/rapleaf/jack/DatabaseConnectionConfiguration.java +++ b/jack-core/src/com/rapleaf/jack/DatabaseConnectionConfiguration.java @@ -187,12 +187,18 @@ private static T load( if (result.isPresent()) { return result.get(); } else { + String foundKeys; + if (map == null) { + foundKeys = "No keys found"; + } else { + foundKeys = map.keySet().toString(); + } throw new RuntimeException( "Unable to find required configuration " + readableName + ". Please set using one of:\n" + "Environment Variable: " + envVar + "\n" + "Java System Property: " + javaProp + "\n" + "Entry in config/" + mapYmlFile + ".yml: " + mapKey + "\n" + - "Found following keys: " + map.keySet()); + "Found following keys: " + foundKeys); } }