From acd87918d2259d5fa61f24ba6229cc92c5197e65 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 17 Jan 2008 15:13:47 +0000 Subject: [PATCH] Implemented hashcode (and equals) to prevent NPE with Spring 2.5 --- .../security/util/InMemoryResource.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/main/java/org/springframework/security/util/InMemoryResource.java b/core/src/main/java/org/springframework/security/util/InMemoryResource.java index eb27be8f66..fd374f1a5b 100644 --- a/core/src/main/java/org/springframework/security/util/InMemoryResource.java +++ b/core/src/main/java/org/springframework/security/util/InMemoryResource.java @@ -16,10 +16,12 @@ package org.springframework.security.util; import org.springframework.core.io.AbstractResource; +import org.springframework.util.Assert; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; /** @@ -46,6 +48,7 @@ public class InMemoryResource extends AbstractResource { } public InMemoryResource(byte[] source, String description) { + Assert.notNull(source); this.source = source; this.description = description; } @@ -59,4 +62,16 @@ public class InMemoryResource extends AbstractResource { public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(source); } + + public int hashCode() { + return source.hashCode(); + } + + public boolean equals(Object res) { + if (res instanceof InMemoryResource) { + return false; + } + + return Arrays.equals(source, ((InMemoryResource)res).source); + } }