Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fix for NPE in BLOBCompressor

orbiter7cd08bd5fb14
diff --git a/source/de/anomic/kelondro/kelondroBLOBCompressor.java b/source/de/anomic/kelondro/kelondroBLOBCompressor.java
index c6b5f9efb..2e7af18a0 100644
--- a/source/de/anomic/kelondro/kelondroBLOBCompressor.java
+++ b/source/de/anomic/kelondro/kelondroBLOBCompressor.java
@@ -120,6 +120,7 @@ public class kelondroBLOBCompressor extends Thread implements kelondroBLOB {
private byte[] decompress(byte[] b) {
// use a magic in the head of the bytes to identify compression type
+ if (b == null) return null;
if (kelondroByteArray.equals(b, gzipMagic)) {
//System.out.print("\\"); // DEBUG
cdr--;
@@ -194,7 +195,10 @@ public class kelondroBLOBCompressor extends Thread implements kelondroBLOB {
public synchronized long length(byte[] key) throws IOException {
byte[] b = buffer.get(new String(key));
if (b != null) return b.length;
- return decompress(this.backend.get(key)).length;
+ b = this.backend.get(key);
+ if (b == null) return 0;
+ b = decompress(b);
+ return (b == null) ? 0 : b.length;
}
private int removeFromQueues(byte[] key) throws IOException {
diff --git a/source/de/anomic/kelondro/kelondroByteArray.java b/source/de/anomic/kelondro/kelondroByteArray.java
index 535849d66..ed8a75a33 100644
--- a/source/de/anomic/kelondro/kelondroByteArray.java
+++ b/source/de/anomic/kelondro/kelondroByteArray.java
@@ -170,13 +170,11 @@ public class kelondroByteArray {
}
public static boolean equals(final byte[] buffer, final byte[] pattern) {
- return equals(buffer, 0, pattern);
- }
-
- public static boolean equals(final byte[] buffer, final int offset, final byte[] pattern) {
// compares two byte arrays: true, if pattern appears completely at offset position
- if (buffer.length < offset + pattern.length) return false;
- for (int i = 0; i < pattern.length; i++) if (buffer[offset + i] != pattern[i]) return false;
+ if (buffer == null && pattern == null) return true;
+ if (buffer == null || pattern == null) return false;
+ if (buffer.length < pattern.length) return false;
+ for (int i = 0; i < pattern.length; i++) if (buffer[i] != pattern[i]) return false;
return true;
}