kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: KAFKA-4300: NamedCache throws an NPE when evict is called and the cache is empty
Date Thu, 13 Oct 2016 20:15:32 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 83116c733 -> 65f6a7964


KAFKA-4300: NamedCache throws an NPE when evict is called and the cache is empty

If evict is called on a NamedCache and the cache is empty an NPE is thrown. This was reported
on the user list from a developer running 0.10.1.

Author: Damian Guy <damian.guy@gmail.com>

Reviewers: Eno Thereska, Matthias J. Sax, Guozhang Wang

Closes #2024 from dguy/cache-bug


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/65f6a796
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/65f6a796
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/65f6a796

Branch: refs/heads/trunk
Commit: 65f6a7964f5e59e789eae3cdd4d301bb6a649064
Parents: 83116c7
Author: Damian Guy <damian.guy@gmail.com>
Authored: Thu Oct 13 13:15:26 2016 -0700
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Thu Oct 13 13:15:26 2016 -0700

----------------------------------------------------------------------
 .../org/apache/kafka/streams/state/internals/NamedCache.java    | 3 +++
 .../apache/kafka/streams/state/internals/NamedCacheTest.java    | 5 +++++
 2 files changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/65f6a796/streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
----------------------------------------------------------------------
diff --git a/streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
b/streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
index a3a0078..65a836e 100644
--- a/streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
+++ b/streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
@@ -190,6 +190,9 @@ class NamedCache {
     }
 
     synchronized void evict() {
+        if (tail == null) {
+            return;
+        }
         final LRUNode eldest = tail;
         currentSizeBytes -= eldest.size();
         if (eldest.entry.isDirty()) {

http://git-wip-us.apache.org/repos/asf/kafka/blob/65f6a796/streams/src/test/java/org/apache/kafka/streams/state/internals/NamedCacheTest.java
----------------------------------------------------------------------
diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/NamedCacheTest.java
b/streams/src/test/java/org/apache/kafka/streams/state/internals/NamedCacheTest.java
index fe11c05..3067256 100644
--- a/streams/src/test/java/org/apache/kafka/streams/state/internals/NamedCacheTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/NamedCacheTest.java
@@ -186,4 +186,9 @@ public class NamedCacheTest {
         assertEquals(Bytes.wrap(new byte[]{2}), iterator.next());
         assertFalse(iterator.hasNext());
     }
+
+    @Test
+    public void shouldNotThrowNullPointerWhenCacheIsEmptyAndEvictionCalled() throws Exception
{
+        cache.evict();
+    }
 }
\ No newline at end of file


Mime
View raw message