From 3d4a5db3d221942654cfeadf17adbc3a66483c63 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 9 Jan 2018 13:48:29 -0800 Subject: [PATCH] Avoid NullPointerException when provider not set Found via spotbugs. --- src/main/java/org/gaul/s3proxy/Main.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gaul/s3proxy/Main.java b/src/main/java/org/gaul/s3proxy/Main.java index 14dd5c6..ae85dc0 100644 --- a/src/main/java/org/gaul/s3proxy/Main.java +++ b/src/main/java/org/gaul/s3proxy/Main.java @@ -264,6 +264,13 @@ public final class Main { String region = properties.getProperty( LocationConstants.PROPERTY_REGION); + if (provider == null) { + System.err.println( + "Properties file must contain: " + + Constants.PROPERTY_PROVIDER); + System.exit(1); + } + if (provider.equals("filesystem") || provider.equals("transient")) { // local blobstores do not require credentials identity = Strings.nullToEmpty(identity); @@ -277,11 +284,12 @@ public final class Main { properties.remove(Constants.PROPERTY_CREDENTIAL); } - if (provider == null || identity == null || credential == null) { - System.err.println("Properties file must contain:\n" + - Constants.PROPERTY_PROVIDER + "\n" + - Constants.PROPERTY_IDENTITY + "\n" + - Constants.PROPERTY_CREDENTIAL + "\n"); + if (identity == null || credential == null) { + System.err.println( + "Properties file must contain: " + + Constants.PROPERTY_IDENTITY + " and " + + Constants.PROPERTY_CREDENTIAL); + System.exit(1); } properties.setProperty(Constants.PROPERTY_USER_AGENT,