Skip to content
Permalink
Browse files

[FIXED JENKINS-46449] Better null safety

  • Loading branch information...
stephenc committed Aug 29, 2017
1 parent d147c66 commit d3391ba0edc70b40cedb8730f3ffff2accb41fa5
@@ -78,7 +78,7 @@ private GitHubSCMFile(@NonNull GitHubSCMFile parent, String name, GHContent meta
}

private void checkOpen() throws IOException {
if (!closable.isOpen()) {
if (!closable.isOpen() || (!resolved && repo == null)) {
throw new IOException("Closed");
}
}
@@ -39,6 +39,7 @@
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.HttpException;

@@ -139,8 +140,22 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
} else if (head instanceof PullRequestSCMHead) {
PullRequestSCMHead pr = (PullRequestSCMHead) head;
if (!pr.isMerge() && pr.getSourceRepo() != null) {
GHUser user = github.getUser(pr.getSourceOwner());
if (user == null) {
// we need to release here as we are not throwing an exception or transferring
// responsibility to FS
Connector.release(github);
return null;
}
GHRepository repo = user.getRepository(pr.getSourceRepo());
if (repo == null) {
// we need to release here as we are not throwing an exception or transferring
// responsibility to FS
Connector.release(github);
return null;
}
return new GitHubSCMFileSystem(
github, github.getUser(pr.getSourceOwner()).getRepository(pr.getSourceRepo()),
github, repo,
pr.getSourceBranch(),
rev);
}
@@ -153,7 +168,18 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
return null;
}

GHRepository repo = github.getUser(src.getRepoOwner()).getRepository(src.getRepository());
GHUser user = github.getUser(src.getRepoOwner());
if (user == null) {
// we need to release here as we are not throwing an exception or transferring responsibility to FS
Connector.release(github);
return null;
}
GHRepository repo = user.getRepository(src.getRepository());
if (repo == null) {
// we need to release here as we are not throwing an exception or transferring responsibility to FS
Connector.release(github);
return null;
}
if (rev == null) {
rev = new AbstractGitSCMSource.SCMRevisionImpl((BranchSCMHead) head, repo.getBranch(ref).getSHA1());
}

0 comments on commit d3391ba

Please sign in to comment.
You can’t perform that action at this time.