git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 3/7] Fix potential NullPointerException in RevWalk.parseTree

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 4, 2008, 23:42 UTC
Message-ID
<1220571739-4219-4-git-send-email-spearce@spearce.org>
In-Reply-To
<1220571739-4219-3-git-send-email-spearce@spearce.org>

If we have previously obtained this RevTree by lookupTree (such as in a commit) but we are missing in the repository and call parseTree we want a MissingObjectException to be thrown, not an NPE. The NPE tells us nothing and could be the same as a bug internal to RevWalk.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/revwalk/RevWalk.java      |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
index 5a29dcf..0dead10 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
@@ -651,7 +651,10 @@ else if (!(c instanceof RevTree))
 
 		if ((t.flags & PARSED) != 0)
 			return t;
-		if (db.openObject(t).getType() != Constants.OBJ_TREE)
+		final ObjectLoader ldr = db.openObject(t);
+		if (ldr == null)
+			throw new MissingObjectException(t, Constants.TYPE_TREE);
+		if (ldr.getType() != Constants.OBJ_TREE)
 			throw new IncorrectObjectTypeException(t, Constants.TYPE_TREE);
 		t.flags |= PARSED;
 		return t;
-- 
1.6.0.1.319.g9f32b
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 4 of 8 in “Misc. RevWalk, bundle transport improvements”
  1. 0/7 Misc. RevWalk, bundle transport improvementsShawn O. Pearce, Sep 4, 2008
  2. 1/7 Cleanup RevWalk.parseCommit, parseTree to not throw ClassCastExceptionShawn O. Pearce, Sep 4, 2008
  3. 2/7 Cleanup RevWalk.parseTree semanticsShawn O. Pearce, Sep 4, 2008
  4. 3/7 Fix potential NullPointerException in RevWalk.parseTreeShawn O. Pearce, Sep 4, 2008
  5. 4/7 Add prerequisite verification to the bundle transportShawn O. Pearce, Sep 4, 2008
  6. 5/7 Include URIish in bundle transport within any TransportExceptionsShawn O. Pearce, Sep 4, 2008
  7. 6/7 Refactor TransportBundle to not be dependent on FileInputStreamShawn O. Pearce, Sep 4, 2008
  8. 7/7 Refactor bundle transport to permit streaming from applicationShawn O. Pearce, Sep 4, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.