Skip to content

Fix GHCommitPointer null repository path and add regression test#2265

Open
n09tal wants to merge 1 commit into
hub4j:mainfrom
n09tal:week9-fix-and-verify
Open

Fix GHCommitPointer null repository path and add regression test#2265
n09tal wants to merge 1 commit into
hub4j:mainfrom
n09tal:week9-fix-and-verify

Conversation

@n09tal
Copy link
Copy Markdown

@n09tal n09tal commented May 17, 2026

Fix issue #2035: handle null repository in GHCommitPointer#getCommit and add regression test.

What changed

  1. src/main/java/org/kohsuke/github/GHCommitPointer.java
  • Updated getCommit() to avoid an uncontrolled NullPointerException path.
  • Added a local repository variable from getRepository().
  • Added a null guard:
    • If repository is null, throw IOException("Cannot commit because repository is null.").
    • Otherwise continue with repository.getCommit(getSha()).
  1. src/test/java/org/kohsuke/github/GHCommitPointerTest.java (new file)
  • Added regression test nullRepoNpe.
  • Test creates a GHCommitPointer with default null repository state.
  • Verifies getCommit() now throws IOException (not NPE).
  • Verifies exception message contains "repository is null".
  1. src/main/java/org/kohsuke/github/GHPullRequest.java
  • Minor inline comment update in getHead() for debugging context.
  • No functional logic change.

Why

Issue #2035 reports an NPE when GHCommitPointer#getCommit() is called and repository data is missing.
This change makes behavior explicit and controlled, and adds test coverage for the null-repository path.

Validation

  • Targeted test command:
    • mvn -Dtest=GHCommitPointerTest#nullRepoNpe test
  • Result:
    • Tests run: 1, Failures: 0, Errors: 0
    • BUILD SUCCESS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants