Community
Participate
Working Groups
Last 2 versions of JGit (5.11 and 5.12) have the following bug that is related to RevWalkUtils#findBranchesReachableFrom. I provide the piece of code to reproduce this bug: ============================================================== public class App { private static final String REMOTE_URL = "https://github.com/a-golubnichenko/RevWalkIssue.git"; private static final String[] COMMIT_IDS = new String[]{ "78d7e33dbdb82d1d303026e8812814b0b0049b68", "4b99b7948a35cb4fa09ed827c2ab81c5686ff2e2", "0ef74d9705d8a7bdf7f41ee778693b262bdb050e" }; public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if (!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } try { // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setBare(true) .setURI(REMOTE_URL) .setCloneAllBranches(true) .setCloneSubmodules(true) .setDirectory(localPath) .call()) { System.out.println("Having repository: " + result.getRepository().getDirectory()); } try (Repository repository = FileRepositoryBuilder.create(localPath); RevWalk revWalk = new RevWalk(repository)) { for (String commitId : COMMIT_IDS) { RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId)); System.out.printf("Message '%s' for commit <%s> %n", revCommit.getFullMessage(), commitId); List<Ref> branchesReachableFrom = RevWalkUtils.findBranchesReachableFrom( revCommit, revWalk, repository.getAllRefs().values()); System.out.println("Reachable branches: " + branchesReachableFrom); } } } finally { // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } } } ============================================================== If the call of RevWalkUtils#findBranchesReachableFrom is commented, the bug will not reproduce. FYI: This code works fine for JGit 5.11. This bug was introduced in JGit 5.12
Stack trace with NPE (for v.5.13) java.lang.NullPointerException at org.eclipse.jgit.util.RawParseUtils.commitMessage(RawParseUtils.java:1218) at org.eclipse.jgit.revwalk.RevCommit.getFullMessage(RevCommit.java:458)
UPD: "Last 2 versions of JGit (5.11 and 5.12)" should be read as "Last 2 versions of JGit (5.12 and 5.13)"