]> source.dussan.org Git - jgit.git/commitdiff
Fix a NullPointerException if properties file doesn't exist 74/16774/2
authorJames Yonan <james@openvpn.net>
Wed, 25 Sep 2013 18:24:16 +0000 (12:24 -0600)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Thu, 13 Feb 2014 23:58:03 +0000 (18:58 -0500)
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 <james@openvpn.net>
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java

index 0a50fe2d290211b70ac4ed8a4955c5ac38e87b60..b3a55a581b01c71bb70247e9ced0137741f55e2b 100644 (file)
@@ -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;
        }