The GrailsConcurrentLinkedMapCache.put method is as follows:
public void put(Object key, Object value) {
this.store.put(key, toStoreValue(value));
}
If I configure the cache to not allow null entries, calling the above with ('aKey', null) will try to put a null value into the underlying ConcurrentLinkedHashMap, which causes a NPE to be thrown by that class's checkNotNull assertion on the value
I was able to get around this be subclassing GrailsConcurrentLinkedMapCache and overriding put with:
@Override
void put(Object key, Object value) {
if (allowNullValues || value) {
nativeCache.put(key, toStoreValue(value))
}
}
If I understand correctly, this was the intended behavior.
Simple test:
void 'test it'() {
given:
GrailsConcurrentLinkedMapCache cache = new GrailsConcurrentLinkedMapCache('name', 10, false)
when:
cache.put('key', null)
then:
null == cache.get('key')
}
yields
java.lang.NullPointerException
at com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.checkNotNull(ConcurrentLinkedHashMap.java:254)
at com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.put(ConcurrentLinkedHashMap.java:718)
at com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.put(ConcurrentLinkedHashMap.java:698)
at grails.plugin.cache.GrailsConcurrentLinkedMapCache.put(GrailsConcurrentLinkedMapCache.java:115)
at com.rgatp.ng.disclosures.api.DecodedInterviewControllerSpec.test it(DecodedInterviewControllerSpec.groovy:19)