Implemented hashcode (and equals) to prevent NPE with Spring 2.5

This commit is contained in:
Luke Taylor 2008-01-17 15:13:47 +00:00
parent a458d21b9f
commit acd87918d2
1 changed files with 15 additions and 0 deletions

View File

@ -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);
}
}