# [JGIT PATCH 2/7] Silence FindBugs "dubious use of GC" in PackFile.mmap

8 messages from 2009-05-04 to 2009-05-06. Participants: Shawn O. Pearce, Sohn, Matthias.
Thread: https://gitlist.dev/t/19181

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 1/7] Fix FindBugs exclude filter to work on UNIX platforms
Message-ID: <1241479848-20687-1-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-1-git-send-email-spearce%40spearce.org

```
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 org.spearce.jgit/.fbprefs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit/.fbprefs b/org.spearce.jgit/.fbprefs
index e97968b..d6f94c3 100644
--- a/org.spearce.jgit/.fbprefs
+++ b/org.spearce.jgit/.fbprefs
@@ -119,7 +119,7 @@ detectorWrongMapIterator=WrongMapIterator|true
 detectorXMLFactoryBypass=XMLFactoryBypass|true
 detector_threshold=2
 effort=default
-excludefilter0=findBugs\\FindBugsExcludeFilter.xml
+excludefilter0=findBugs/FindBugsExcludeFilter.xml
 filter_settings=Medium|BAD_PRACTICE,CORRECTNESS,MT_CORRECTNESS,PERFORMANCE,STYLE|false
 filter_settings_neg=MALICIOUS_CODE,NOISE,I18N,SECURITY,EXPERIMENTAL|
 run_at_full_build=true
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 2/7] Silence FindBugs "dubious use of GC" in PackFile.mmap
Message-ID: <1241479848-20687-2-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-2-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-1-git-send-email-spearce@spearce.org>

```
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../findBugs/FindBugsExcludeFilter.xml             |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/findBugs/FindBugsExcludeFilter.xml b/org.spearce.jgit/findBugs/FindBugsExcludeFilter.xml
index 526eb01..2af9348 100644
--- a/org.spearce.jgit/findBugs/FindBugsExcludeFilter.xml
+++ b/org.spearce.jgit/findBugs/FindBugsExcludeFilter.xml
@@ -6,4 +6,13 @@
        <Method name="refreshPackedRefs" />
        <Bug pattern="DM_STRING_CTOR" />
      </Match>
+
+     <!-- Silence PackFile.mmap calls GC, we need to force it to remove stale
+          memory mapped segments if the JVM heap is out of address space.
+       -->
+     <Match>
+       <Class name="org.spearce.jgit.lib.PackFile" />
+       <Method name="mmap" />
+       <Bug pattern="DM_GC" />
+     </Match>
 </FindBugsFilter>
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 3/7] Fix FindBugs String == is bad form
Message-ID: <1241479848-20687-3-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-3-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-2-git-send-email-spearce@spearce.org>

```
We only used "a == b" to test for both values == null, as we can't
use a.equalsIgnoreCase if a is null.  Instead test for that null
case, and fall through for everything else.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/RepositoryConfig.java |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
index 87fc254..cb287ee 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
@@ -1102,7 +1102,7 @@ boolean match(final String aBase, final String aExtendedBase,
 		}
 
 		private static boolean eq(final String a, final String b) {
-			if (a == b)
+			if (a == null && b == null)
 				return true;
 			if (a == null || b == null)
 				return false;
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 4/7] Fix FindBugs load known null value
Message-ID: <1241479848-20687-4-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-4-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-3-git-send-email-spearce@spearce.org>

```
We know its null, so use the null constant instead of the null
variable here.  Either way is pretty clear to the reader, but
this form makes FindBugs be quiet.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
index bcbdbb0..d3c43da 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
@@ -314,9 +314,8 @@ private static boolean inList(final PackFile[] list, final PackFile pack) {
 
 	private PackFile[] packs() {
 		PackFile[] r = packList.get();
-		if (r == null) {
-			r = scanPacks(r);
-		}
+		if (r == null)
+			r = scanPacks(null);
 		return r;
 	}
 
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 5/7] FindBugs: Fix use of byte[].toString() in error messages
Message-ID: <1241479848-20687-5-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-5-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-4-git-send-email-spearce@spearce.org>

```
We meant to use typeString here, not encodedTypeString, as we want
a human-readable string form of the object type for display into
an exception message.  FindBugs caught us using a byte[] here and
not a string, resulting in a useless portion of the message text.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/transport/IndexPack.java  |    2 +-
 .../jgit/transport/WalkFetchConnection.java        |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
index 7881124..b2bcbb7 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
@@ -744,7 +744,7 @@ private void verifySafeObject(final AnyObjectId id, final int type,
 				objCheck.check(type, data);
 			} catch (CorruptObjectException e) {
 				throw new IOException("Invalid "
-						+ Constants.encodedTypeString(type) + " " + id.name()
+						+ Constants.typeString(type) + " " + id.name()
 						+ ":" + e.getMessage());
 			}
 		}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/WalkFetchConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/WalkFetchConnection.java
index 06b2c87..4d14305 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/WalkFetchConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/WalkFetchConnection.java
@@ -602,7 +602,7 @@ private void verifyLooseObject(final AnyObjectId id, final byte[] compressed)
 		if (!AnyObjectId.equals(id, idBuffer)) {
 			throw new TransportException("Incorrect hash for " + id.name()
 					+ "; computed " + idBuffer.name() + " as a "
-					+ Constants.encodedTypeString(uol.getType()) + " from "
+					+ Constants.typeString(uol.getType()) + " from "
 					+ compressed.length + " bytes.");
 		}
 		if (objCheck != null) {
@@ -610,7 +610,7 @@ private void verifyLooseObject(final AnyObjectId id, final byte[] compressed)
 				objCheck.check(uol.getType(), uol.getCachedBytes());
 			} catch (CorruptObjectException e) {
 				throw new TransportException("Invalid "
-						+ Constants.encodedTypeString(uol.getType()) + " "
+						+ Constants.typeString(uol.getType()) + " "
 						+ id.name() + ":" + e.getMessage());
 			}
 		}
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 6/7] Make TransportLocal.StreamRewritingThread static
Message-ID: <1241479848-20687-6-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-6-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-5-git-send-email-spearce@spearce.org>

```
This thread doesn't need access to the outer instance.

Noticed by FindBugs.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../org/spearce/jgit/transport/TransportLocal.java |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java
index dae8951..cffdba1 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java
@@ -363,7 +363,7 @@ public void close() {
 		}
 	}
 
-	class StreamRewritingThread extends Thread {
+	static class StreamRewritingThread extends Thread {
 		private final InputStream in;
 
 		StreamRewritingThread(final String cmd, final InputStream in) {
-- 
1.6.3.rc4.206.g03e16

```

## Shawn O. Pearce, 2009-05-04 23:30

Subject: [JGIT PATCH 7/7] FindBugs: Disable clone() idiom tests
Message-ID: <1241479848-20687-7-git-send-email-spearce@spearce.org>
URL: https://gitlist.dev/e/1241479848-20687-7-git-send-email-spearce%40spearce.org
In-Reply-To: <1241479848-20687-6-git-send-email-spearce@spearce.org>

```
We tend not to implement Cloneable, but instead define our own
form of clone() on objects that we want to permit making clones
of.  This is because Cloneable is a rather poor interface in
the JVM with its implicit field copying, but the method name
is the right name for us.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 org.spearce.jgit/.fbprefs |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit/.fbprefs b/org.spearce.jgit/.fbprefs
index d6f94c3..81a0767 100644
--- a/org.spearce.jgit/.fbprefs
+++ b/org.spearce.jgit/.fbprefs
@@ -1,5 +1,5 @@
 #FindBugs User Preferences
-#Mon May 04 20:17:32 CEST 2009
+#Mon May 04 16:24:13 PDT 2009
 detectorAppendingToAnObjectOutputStream=AppendingToAnObjectOutputStream|true
 detectorBadAppletConstructor=BadAppletConstructor|false
 detectorBadResultSetAccess=BadResultSetAccess|true
@@ -10,7 +10,7 @@ detectorBooleanReturnNull=BooleanReturnNull|true
 detectorCallToUnsupportedMethod=CallToUnsupportedMethod|true
 detectorCheckImmutableAnnotation=CheckImmutableAnnotation|true
 detectorCheckTypeQualifiers=CheckTypeQualifiers|true
-detectorCloneIdiom=CloneIdiom|true
+detectorCloneIdiom=CloneIdiom|false
 detectorComparatorIdiom=ComparatorIdiom|true
 detectorConfusedInheritance=ConfusedInheritance|true
 detectorConfusionBetweenInheritedAndOuterMethod=ConfusionBetweenInheritedAndOuterMethod|true
-- 
1.6.3.rc4.206.g03e16

```

## Sohn, Matthias, 2009-05-06 11:18

Subject: RE: [JGIT PATCH 1/7] Fix FindBugs exclude filter to work on UNIX platforms
Message-ID: <366BBB1215D0AB4B8A153AF047A28780030C8A5C@dewdfe18.wdf.sap.corp>
URL: https://gitlist.dev/e/366BBB1215D0AB4B8A153AF047A28780030C8A5C%40dewdfe18.wdf.sap.corp
In-Reply-To: <1241479848-20687-1-git-send-email-spearce@spearce.org>

```
Shawn O. Pearce [mailto:spearce@spearce.org] wrote:
> Subject: [JGIT PATCH 1/7] Fix FindBugs exclude filter to work on UNIX
> platforms
Thanks, I missed this. I reported this problem to FindBugs :
https://sourceforge.net/tracker/index.php?func=detail&aid=2787728&group_id=96405&atid=614693

--
Matthias

```
