소스 검색

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

Luke Taylor 17 년 전
부모
커밋
acd87918d2
1개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      core/src/main/java/org/springframework/security/util/InMemoryResource.java

+ 15 - 0
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);
+    }
 }