You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by "mmeusey (via GitHub)" <gi...@apache.org> on 2025/04/17 16:36:24 UTC

[I] Error in GrailsConcurrentLinkedMapCache.put when excluding null values (v 4.0.0) [grails-core]

mmeusey opened a new issue, #14167:
URL: https://github.com/apache/grails-core/issues/14167

   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)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org