Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in GrailsConcurrentLinkedMapCache.put when excluding null values (v 4.0.0) #67

Open
mmeusey opened this issue Oct 28, 2019 · 0 comments

Comments

@mmeusey
Copy link

mmeusey commented Oct 28, 2019

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)

@mmeusey mmeusey changed the title Error in GrailsConcurrentLinkedMapCache.put when excluding null values Error in GrailsConcurrentLinkedMapCache.put when excluding null values (v 4.0.0) Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant