Bug 576285 - Call of RevWalkUtils#findBranchesReachableFrom produces NPE in RevCommit#getFullMessage
Summary: Call of RevWalkUtils#findBranchesReachableFrom produces NPE in RevCommit#getF...
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.12   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-27 09:51 EDT by Artem Golubnichenko CLA
Modified: 2021-09-27 11:12 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Artem Golubnichenko CLA 2021-09-27 09:51:00 EDT
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
Comment 1 Artem Golubnichenko CLA 2021-09-27 10:32:43 EDT
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)
Comment 2 Artem Golubnichenko CLA 2021-09-27 11:12:22 EDT
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)"