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

[JGIT PATCH (RESEND) 2/3] Work around Sun javac compiler error in RefUpdate

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 1, 2009, 23:16 UTC
Message-ID
<1251847010-9992-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1251847010-9992-1-git-send-email-spearce@spearce.org>

Sun's javac, version 5 and 6, apparently miscompiles the for loop which is looking for a conflicting ref name in the existing set of refs for this repository.

Debugging this code showed the control flow to return LOCK_FAILURE when startsWith returned false, which is highly illogical and the exact opposite of what we have written here.

Sun's javap tool was unable to disassemble the compiled method. Instead it simply failed to produce anything about updateImpl. So my remark about the code being compiled wrong is only a guess based on how I observed the behavior, and not by actually studying the resulting instructions.

Eclipse's JDT appears to have compiled the updateImpl method correctly, and produces a working executable. But this is a much less common compiler to build Java libraries with.

This refactoring to extract the name conflicting test out into its own method appears to work around the Sun javac bug, and the resulting class works correctly with either compiler. The code is also more clear, so its a gain either way.

Signed-off-by: Shawn O. Pearce <sop@google.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/RefUpdate.java        |   26 +++++++++++++-------
 1 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
index 8dffed2..8226e10 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
@@ -449,15 +449,8 @@ private Result updateImpl(final RevWalk walk, final Store store)
 		RevObject newObj;
 		RevObject oldObj;
 
-		int lastSlash = getName().lastIndexOf('/');
-		if (lastSlash > 0)
-			if (db.getRepository().getRef(getName().substring(0, lastSlash)) != null)
-				return Result.LOCK_FAILURE;
-		String rName = getName() + "/";
-		for (Ref r : db.getAllRefs().values()) {
-			if (r.getName().startsWith(rName))
-				return Result.LOCK_FAILURE;
-		}
+		if (isNameConflicting())
+			return Result.LOCK_FAILURE;
 		lock = new LockFile(looseFile);
 		if (!lock.lock())
 			return Result.LOCK_FAILURE;
@@ -490,6 +483,21 @@ private Result updateImpl(final RevWalk walk, final Store store)
 		}
 	}
 
+	private boolean isNameConflicting() throws IOException {
+		final String myName = getName();
+		final int lastSlash = myName.lastIndexOf('/');
+		if (lastSlash > 0)
+			if (db.getRepository().getRef(myName.substring(0, lastSlash)) != null)
+				return true;
+
+		final String rName = myName + "/";
+		for (Ref r : db.getAllRefs().values()) {
+			if (r.getName().startsWith(rName))
+				return true;
+		}
+		return false;
+	}
+
 	private static RevObject safeParse(final RevWalk rw, final AnyObjectId id)
 			throws IOException {
 		try {
-- 
1.6.4.1.341.gf2a44
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 7 in “Allow RefUpdate.setExpectedOldObjectId to accept RevCommit”
  1. 1/3 Allow RefUpdate.setExpectedOldObjectId to accept RevCommitShawn O. Pearce, Sep 1, 2009
  2. 2/3 Work around Sun javac compiler error in RefUpdateShawn O. Pearce, Sep 1, 2009
  3. 3/3 Fix DirCache.findEntry to work on an empty cacheShawn O. Pearce, Sep 1, 2009
  4. Robin RosenbergSep 3, 2009
  5. Shawn O. PearceSep 3, 2009
  6. Nicolas PitreSep 4, 2009
  7. Shawn O. PearceSep 1, 2009

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.