summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-02-24 17:30:37 -0800
committerElliott Hughes <enh@google.com>2011-02-24 17:30:37 -0800
commitb16edf548fa6bb9cd93b238e7820bc92195e5e2f (patch)
treef9c528d204f3910117079d47fbc23073755d2f88 /luni
parentc0009b516f3341c678ef5f82cdffd6f9872bc22a (diff)
downloadlibcore-b16edf548fa6bb9cd93b238e7820bc92195e5e2f.zip
libcore-b16edf548fa6bb9cd93b238e7820bc92195e5e2f.tar.gz
libcore-b16edf548fa6bb9cd93b238e7820bc92195e5e2f.tar.bz2
Fix more FindBugs warnings: BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS.
"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." Change-Id: Ib16eb57e8876ec117634b4c9b069a4dccc61c657
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java10
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java24
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ByteArray.java44
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContext.java14
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java18
5 files changed, 58 insertions, 52 deletions
diff --git a/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java b/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
index 5a016e9..f524eb3 100644
--- a/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
+++ b/luni/src/main/java/javax/security/auth/PrivateCredentialPermission.java
@@ -382,9 +382,13 @@ public final class PrivateCredentialPermission extends Permission {
// Checks two CredOwner objects for equality.
@Override
- public boolean equals(Object obj) {
- return principalClass.equals(((CredOwner) obj).principalClass)
- && principalName.equals(((CredOwner) obj).principalName);
+ public boolean equals(Object o) {
+ if (!(o instanceof CredOwner)) {
+ return false;
+ }
+ CredOwner lhs = (CredOwner) o;
+ return principalClass.equals(lhs.principalClass) &&
+ principalName.equals(lhs.principalName);
}
// Returns the hash code value for this object.
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
index 8ee8a33..5d45039 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
@@ -292,28 +292,4 @@ abstract class AbstractSessionContext implements SSLSessionContext {
super.finalize();
}
}
-
- /**
- * Byte array wrapper. Implements equals() and hashCode().
- */
- static class ByteArray {
-
- private final byte[] bytes;
-
- ByteArray(byte[] bytes) {
- this.bytes = bytes;
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(bytes);
- }
-
- @Override
- @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
- public boolean equals(Object o) {
- ByteArray other = (ByteArray) o;
- return Arrays.equals(bytes, other.bytes);
- }
- }
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ByteArray.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ByteArray.java
new file mode 100644
index 0000000..8a000c5
--- /dev/null
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ByteArray.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.util.Arrays;
+
+/**
+ * Byte array wrapper for hashtable use. Implements equals() and hashCode().
+ */
+final class ByteArray {
+ private final byte[] bytes;
+ private final int hashCode;
+
+ ByteArray(byte[] bytes) {
+ this.bytes = bytes;
+ this.hashCode = Arrays.hashCode(bytes);
+ }
+
+ @Override public int hashCode() {
+ return hashCode;
+ }
+
+ @Override public boolean equals(Object o) {
+ if (!(o instanceof ByteArray)) {
+ return false;
+ }
+ ByteArray lhs = (ByteArray) o;
+ return Arrays.equals(bytes, lhs.bytes);
+ }
+}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContext.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContext.java
index 9f4c4db..0b358aa 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContext.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContext.java
@@ -130,16 +130,16 @@ public class ClientSessionContext extends AbstractSessionContext {
this.port = port;
}
- @Override
- public int hashCode() {
+ @Override public int hashCode() {
return host.hashCode() * 31 + port;
}
- @Override
- @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
- public boolean equals(Object o) {
- HostAndPort other = (HostAndPort) o;
- return host.equals(other.host) && port == other.port;
+ @Override public boolean equals(Object o) {
+ if (!(o instanceof HostAndPort)) {
+ return false;
+ }
+ HostAndPort lhs = (HostAndPort) o;
+ return host.equals(lhs.host) && port == lhs.port;
}
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
index e8aa7bb..90baa87 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
@@ -138,22 +138,4 @@ public final class IndexedPKIXParameters extends PKIXParameters {
}
return false;
}
-
- /**
- * Wraps a byte[] and adds equals() and hashCode() support.
- */
- static class Bytes {
- final byte[] bytes;
- final int hash;
- Bytes(byte[] bytes) {
- this.bytes = bytes;
- this.hash = Arrays.hashCode(bytes);
- }
- @Override public int hashCode() {
- return hash;
- }
- @Override public boolean equals(Object o) {
- return Arrays.equals(bytes, ((Bytes) o).bytes);
- }
- }
}