Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] [PATCH] Fix a NullPointerException if properties file doesn't exist.

please push your patch to Gerrit for code review as described in the contributor guide
http://wiki.eclipse.org/EGit/Contributor_Guide#Contributing_Patches

--
Matthias


On Mon, Sep 23, 2013 at 10:19 PM, James Yonan <james@xxxxxxxxxxx> wrote:
For example with following URL,

  amazon-s3://.jgit@mybucket/foo.git

if ~/.jgit is missing, code will throw a NullPointerException.

With this patch, a reasonable error message will be emitted:

  fatal: Cannot read file /Users/jamesyonan/.jgit

Signed-off-by: James Yonan <james@xxxxxxxxxxx>
---
 .../src/org/eclipse/jgit/transport/TransportAmazonS3.java      | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

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 0a50fe2..b3a55a5 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 @@ private Properties loadProperties() throws NotSupportedException {
                        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;
        }

--
1.8.1.2

_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jgit-dev


Back to the top