Skip to content

Commit

Permalink
fix for NPE in BLOBCompressor
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5388 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Dec 11, 2008
1 parent 5b94498 commit 7cd08bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion source/de/anomic/kelondro/kelondroBLOBCompressor.java
Expand Up @@ -120,6 +120,7 @@ private byte[] markWithPlainMagic(byte[] b) {

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--;
Expand Down Expand Up @@ -194,7 +195,10 @@ public synchronized long length() {
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 {
Expand Down
10 changes: 4 additions & 6 deletions source/de/anomic/kelondro/kelondroByteArray.java
Expand Up @@ -170,13 +170,11 @@ public void write(final int to_position, final kelondroByteArray from_array, fin
}

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

Expand Down

0 comments on commit 7cd08bd

Please sign in to comment.