NullPointerException

Dustin Sallings dustin at spy.net
Mon Oct 15 17:36:50 UTC 2007


On Oct 15, 2007, at 9:32 , Chris Lamprecht wrote:

> private Map<String, Object> getStuff(Collection<Integer> ids) {
>     StringBuilder buf = new StringBuilder(500);
>     for (int id : ids) {
>         buf.append("cacheditem:").append(id).append(' ');
>     }
>     String request = buf.toString().trim();
>     Map<String, Object> map = memcache.getBulk(request);
>     log.debug("Requested "+ids.size()+" items from cache, got  
> "+map.size()+" items back");
>     return map;
> }

	Ah.  The bug is that I'm not validating keys in get bulk.  You're  
passing in a single key with spaces in it.

	I'll make sure these are validated, but in the meantime, this is how  
your code should look:

private Map<String, Object> getStuff(Collection<Integer> ids) {
     Set<String> keys=new HashSet<String>();
     for (int id : ids) {
	keys.add("cacheditem:" + id);
     }
     Map<String, Object> map = memcache.getBulk(keys);
     log.debug("Requested "+ids.size()+" items from cache, got  
"+map.size()+" items back");
     return map;
}


-- 
Dustin Sallings


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20071015/773efd31/attachment.html


More information about the memcached mailing list