From: James Yonan Date: Wed, 25 Sep 2013 18:24:16 +0000 (-0600) Subject: Fix a NullPointerException if properties file doesn't exist X-Git-Tag: v3.3.0.201402191814-rc1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bb7299e8a815ac7884f429e3bc710e0c27c121c;p=jgit.git Fix a NullPointerException if properties file doesn't exist For example with following URL, amazon-s3://.jgit@mybucket/foo.git if ~/.jgit is missing, jgit command will throw a NullPointerException. With this patch, a reasonable error message will be emitted: fatal: Cannot read file /Users/jamesyonan/.jgit Change-Id: I1d366f2d55e170d2972715c657c8e2d10c8d87d2 Signed-off-by: James Yonan --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 0a50fe2d29..b3a55a581b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -170,8 +170,14 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { return loadPropertiesFile(propsFile); Properties props = new Properties(); - props.setProperty("accesskey", uri.getUser()); //$NON-NLS-1$ - props.setProperty("secretkey", uri.getPass()); //$NON-NLS-1$ + String user = uri.getUser(); + String pass = uri.getPass(); + if (user != null && pass != null) { + props.setProperty("accesskey", user); //$NON-NLS-1$ + props.setProperty("secretkey", pass); //$NON-NLS-1$ + } else + throw new NotSupportedException(MessageFormat.format( + JGitText.get().cannotReadFile, propsFile)); return props; }