Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Call of RevWalkUtils#findBranchesReachableFrom produces NPE in RevCommit#getFullMessage

Hello,

Last 2 versions of JGit (5.12 and 5.13) 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 {
        File localPath = File.createTempFile("TestGitRepository", "");
        if (!localPath.delete()) {
            throw new IOException("Could not delete temporary file " + localPath);
        }

        try {
            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 {
            FileUtils.deleteDirectory(localPath);
        }
    }
}
==============================================================

The provided piece of code produces the following 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)

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.

--
Best regards,
Artem Golubnichenko

Back to the top