SOLR-3791: CachedSqlEntityProcessor throws NPE when pk column is Null

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1384819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-09-14 15:26:28 +00:00
parent e312ee6bfa
commit 71a8203a06
3 changed files with 45 additions and 0 deletions

View File

@ -170,6 +170,9 @@ Bug Fixes
* SOLR-3779: DataImportHandler's LineEntityProcessor when used in conjunction
with FileListEntityProcessor would only process the first file.
(Ahmet Arslan via James Dyer)
* SOLR-3791: CachedSqlEntityProcessor would throw a NullPointerException when
a query returns a row with a NULL key. (Steffen Moelter via James Dyer)
Other Changes
----------------------

View File

@ -54,6 +54,10 @@ public class SortedMapBackedCache implements DIHCache {
}
pk = c.iterator().next();
}
//Rows with null keys are not added.
if(pk==null) {
return;
}
List<Map<String,Object>> thisKeysRecs = theMap.get(pk);
if (thisKeysRecs == null) {
thisKeysRecs = new ArrayList<Map<String,Object>>();
@ -87,6 +91,9 @@ public class SortedMapBackedCache implements DIHCache {
public void delete(Object key) {
checkOpen(true);
checkReadOnly();
if(key==null) {
return;
}
theMap.remove(key);
}
@ -120,6 +127,9 @@ public class SortedMapBackedCache implements DIHCache {
@Override
public Iterator<Map<String,Object>> iterator(Object key) {
checkOpen(true);
if(key==null) {
return null;
}
if(key instanceof Iterable<?>) {
List<Map<String,Object>> vals = new ArrayList<Map<String,Object>>();
Iterator<?> iter = ((Iterable<?>) key).iterator();

View File

@ -20,6 +20,7 @@ package org.apache.solr.handler.dataimport;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -71,6 +72,37 @@ public class TestSortedMapBackedCache extends AbstractDIHCacheTestCase {
}
}
}
@Test
public void testNullKeys() throws Exception {
//A null key should just be ignored, but not throw an exception
DIHCache cache = null;
try {
cache = new SortedMapBackedCache();
Map<String, String> cacheProps = new HashMap<String, String>();
cacheProps.put(DIHCacheSupport.CACHE_PRIMARY_KEY, "a_id");
cache.open(getContext(cacheProps));
Map<String,Object> data = new HashMap<String,Object>();
data.put("a_id", null);
data.put("bogus", "data");
cache.add(data);
Iterator<Map<String, Object>> cacheIter = cache.iterator();
while (cacheIter.hasNext()) {
Assert.fail("cache should be empty.");
}
Assert.assertNull(cache.iterator(null));
cache.delete(null);
} catch (Exception e) {
throw e;
} finally {
try {
cache.destroy();
} catch (Exception ex) {
}
}
}
@Test
public void testCacheReopensWithUpdate() {