package org.kohsuke.github;

/**
 * A branch in a repository.
 * 
 * @author Yusuke Kokubo
 */
public class GHBranch {
    private GitHub root;
    private GHRepository owner;

    private String name;
    private Commit commit;

    public static class Commit {
        String sha,url;
    }

    public GitHub getRoot() {
        return root;
    }

    /**
     * Repository that this branch is in.
     */
    public GHRepository getOwner() {
        return owner;
    }

    public String getName() {
        return name;
    }

    /**
     * The commit that this branch currently points to.
     */
    public String getSHA1() {
        return commit.sha;
    }

    @Override
    public String toString() {
        final String url = owner != null ? owner.getUrl().toString() : "unknown";
        return "Branch:" + name + " in " + url;
    }

    /*package*/ GHBranch wrap(GHRepository repo) {
        this.owner = repo;
        this.root = repo.root;
        return this;
    }
}

package org.kohsuke.github;

/**
 * A branch in a repository.
 * 
 * @author Yusuke Kokubo
 */
public class GHBranch {
    private GitHub root;
    private GHRepository owner;

    private String name;
    private Commit commit;

    public static class Commit {
        String sha,url;
    }

    public GitHub getRoot() {
        return root;
    }

    /**
     * Repository that this branch is in.
     */
    public GHRepository getOwner() {
        return owner;
    }

    public String getName() {
        return name;
    }

    /**
     * The commit that this branch currently points to.
     */
    public String getSHA1() {
        return commit.sha;
    }

    @Override
    public String toString() {
        return "Branch:" + name + " in " + owner.getUrl();
    }

    /*package*/ GHBranch wrap(GHRepository repo) {
        this.owner = repo;
        this.root = repo.root;
        return this;
    }
}

--- 
+++ 
@@ -40,7 +40,8 @@
 
     @Override
     public String toString() {
-        return "Branch:" + name + " in " + owner.getUrl();
+        final String url = owner != null ? owner.getUrl().toString() : "unknown";
+        return "Branch:" + name + " in " + url;
     }
 
     /*package*/ GHBranch wrap(GHRepository repo) {
Fix potential NPE in the code
