threads / patch / 19121

patchEquals method should not assume anything about the type of its argument

Subject: [PATCH JGIT] Equals method should not assume anything about the type of its argument

## tl;dr

2 messages between Apr 29, 2009 and Apr 29, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Sohn, Matthias· Apr 29, 2009, 14:54 UTC · lore
The equals(Object o) method shouldn't make any assumptions about the type of o. It should simply return false if o is not the same type as this.
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
---
 .../src/org/spearce/jgit/lib/AnyObjectId.java      |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java +5 −1
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
index 2e3a43e..0bd2288 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
@@ -253,7 +253,11 @@ public boolean equals(final AnyObjectId other) {
 	}
 
 	public boolean equals(final Object o) {
-		return equals((AnyObjectId) o);
+		if (o instanceof AnyObjectId) {
+			return equals((AnyObjectId) o);
+		} else {
+			return false;
+		}
 	}
 
 	/**
-- 
1.6.2.2.1669.g7eaf8
Shawn O. Pearce· Apr 29, 2009, 15:02 UTC · re: Sohn, Matthias · lore

Re: [PATCH JGIT] Equals method should not assume anything about the type of its argument

"Sohn, Matthias" <matthias.sohn@sap.com> wrote:
> The equals(Object o) method shouldn't make any assumptions about the type of o. It should simply return false if o is not the same type as this.
True.
Please line wrap your commit message at ~70 columns wide.
 
> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>

FWIW, your From header in the emails comes out "Sohn, Matthias" while your Signed-off-By is as above. This means that when I slam your patch through git-am I get an author name of "Sohn, Matthias", which looks damn funny. I have to remember to edit the patch after the fact to make it come out correct.

Any change you can get your MUA to behave better? Or is this Exchange enforcing a nice uniform standard... *sigh*

Show 15 quoted lines
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
> index 2e3a43e..0bd2288 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
> @@ -253,7 +253,11 @@ public boolean equals(final AnyObjectId other) {
>  	}
>  
>  	public boolean equals(final Object o) {
> -		return equals((AnyObjectId) o);
> +		if (o instanceof AnyObjectId) {
> +			return equals((AnyObjectId) o);
> +		} else {
> +			return false;
> +		}
>  	}
Style nit: We avoid unnecessary braces around clauses.
-- 
Shawn.

← back to recent threads