Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] [Internet] Call of RevWalkUtils#findBranchesReachableFrom produces NPE in RevCommit#getFullMessage
  • From: "Adithya Chakilam (QUIC)" <quic_achakila@xxxxxxxxxxx>
  • Date: Wed, 17 Nov 2021 00:29:04 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=quicinc.com; dmarc=pass action=none header.from=quicinc.com; dkim=pass header.d=quicinc.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4bns8GNUtYiMI4nXz4QZiugL27eUs0kNGR7SfOz78XQ=; b=Yf95ms4qlL+I4aN+Ay4FV4IZUNSCRQtbqmdOiHwo4pEgTO/q709JpkcgF/oEEoiri/dmst88+wVdwS47iNZvnczMl8dDC7aBD8FJRyklw25+hJmpscK+xBFVU8Yxc2uaQ/75oWadtMvzIcKuIze0D8doY4rfwzLY4jgjnZTOg9gcXuj5z0iY5TDitUrRHaJbBZmQfB73X4EzN8VmXf4f6KOeq34zwD/ZmNtdmiL0DlOxICwbG94uz2iZD3qVlSQabmPRQ59nRl7n5/fLj7eH1u4ww6iCgGEpIJ/bwZqRRcFONUr1gElarrorK5nOgUcDbpwoWNJ53pmDPWKCsANtHA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SA897YjQEvMhnRVnhparwgMhvI6r9gVOg+gin6+VSUEXgdFnvCYW2ya183W6+ZnY8E1qW8yXwojZtHUjEGH6hWRIr5FAWpaj58Zua2xA/phL2TD9Oy89vlVf4lzNy+XaU0yM4T0eAUxuZm1/MkbYFbll2Gi5ynNBXrL62H04OLJJ/dN/+9VIYLIxZW/Fqjkc24rkbFZmNYEcmDxCwvNBYx9aETAFEa1TiZ/XmTbQ/hcdKDdvJ9Naxa18a1GKy3/X2yERWmEoYqOMEFrrMCRHZ5VtzLescg1PW6QESOwSBRI1c14Lpzx1m/o7iSm9YYTgV2LzLFPR40zxR4X3WHbE3Q==
  • Delivered-to: jgit-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jgit-dev/>
  • List-help: <mailto:jgit-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jgit-dev>, <mailto:jgit-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jgit-dev>, <mailto:jgit-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHX20ogctTVVBvThESBmhTHYI8CZg==
  • Thread-topic: [jgit-dev] [Internet] Call of RevWalkUtils#findBranchesReachableFrom produces NPE in RevCommit#getFullMessage

This was introduced in [1] when we were optimizing that RevWalkUtils.findBranchesReachableFrom() by using getMergedInto() API. The walk is now done using PendingGenerator which disposes body of parent commits being added. It used to be done by MergeBaseGenerator with the previous isMergedInto() API.


Thanks
Adithya

On Nov 15, 2021, at 8:10 PM, kylezhao(赵柯宇) <kylezhao@xxxxxxxxxxx> wrote:

WARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
RevWalkUtils#findBranchesReachableFrom() internal called the RevCommit#disposeBody method, in order to reduce the memory usage. This problem occurs in many places where commit traversal is involved. It could cause some commits to not contain body content.

I personally understand RevWalk#parseCommit and  RevWalk#parseHeaders are usually only guarantee that we get the header information for the commit.
To ensure that the body information is obtained for the commit, we can call RevWalk#parseBody


For example:
=======================================================================

       try (Repository repository = FileRepositoryBuilder.create(localPath);
                 RevWalk revWalk = new RevWalk(repository)) {
                for (String commitId : COMMIT_IDS) {
                    RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId));
                    rewalk.parseBody(revCommit); // parse the commit body
                    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);
                }
            }

--
Regards,
Kyle

发件人: jgit-dev <jgit-dev-bounces@xxxxxxxxxxx> 代表 Artem Golubnichenko <artem.golubnichenko@xxxxxxxxx>
发送时间: 2021年11月16日 4:02:34
收件人: jgit-dev@xxxxxxxxxxx
主题: [Internet][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
_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jgit-dev


Back to the top