[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Ehcache does not allow key attributes with null values  XML
Forum Index -> Ehcache
Author Message
mdhuper

neo

Joined: 05/07/2014 10:12:18
Messages: 2
Offline

We are using ehcache(2.7.2) for our caching purposes.

Here is my configuration

Code:
<cache name="MyMessage" maxElementsInMemory="1000" eternal="false"
 		timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="false"
 		maxElementsOnDisk="0" diskPersistent="false"
 		diskExpiryThreadIntervalSeconds="1800" memoryStoreEvictionPolicy="LRU">
 		<cacheEventListenerFactory
 			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
 		<searchable keys="false" values="false">
 			<searchAttribute name="myAppId" expression="key.getAppId()" />
 			<searchAttribute name="myTenId" expression="key.getTenantId()" />
 			<searchAttribute name="myEntityId" expression="key.getParticipatingEntityId()" />
 			<searchAttribute name="myTransactionId" expression="key.getTransactionId()" />
 			<searchAttribute name="application" expression="key.getApplication()" />
 			<searchAttribute name="message" expression="key.getMessage()"/>
 		</searchable>
 
 	</cache>


It works fine for normal operations such as remove, get, remove by partial key etc. However when I try to insert a key-value pair with key as MyMessage object and specify an attribute value as null, I get null pointer exception from Ehcache code. Is there a reason why this is limited ? Is there any workaround for this limitation ?
teck

seraphim
[Avatar]
Joined: 05/24/2006 15:03:25
Messages: 1128
Offline

Can you post the exception stacktrace? From your description alone it sounds like maybe the Element you are put()'ing to the cache has a null key (which is not legal in general and will also give an NPE evaluating the attribute expression which references the null key)



Tim Eck (terracotta engineer)
mdhuper

neo

Joined: 05/07/2014 10:12:18
Messages: 2
Offline

I am sorry let me rephrase this question. We can successfully put the key with null attributes, however we cannot search and remove by partial key using the null value. For example we want to remove all keys with a particular attribute as null. Here is the stack trace that we have

Code:
12:52:47,188 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/cf-test-webapp].[CacheServlet]] (http-/127.0.0.1:9080-1) JBWEB000236: Servlet.se
 ice() for servlet CacheServlet threw exception: java.lang.NullPointerException
         at net.sf.ehcache.search.expression.EqualTo.<init>(EqualTo.java:45) [ehcache-2.7.2.jar:2.7.2]
         at net.sf.ehcache.search.Attribute.eq(Attribute.java:158) [ehcache-2.7.2.jar:2.7.2]
         at com.MyApp.cache.EhCacheImpl.removeByMatchingKeyAttributes(EhCacheImpl.java:135) [optum-hie-framework-0.9.8.jar:]
         at com.test.CacheServlet.doGet(CacheServlet.java:277) [classes:]
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322) [spring-security-web-3.1.1.RELEASE.jar:3.1.1.RELEASE
         at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) [spring-security-web-3.1.1.RELEASE.jar
 .1.1.RELEASE]



Is this some limitation imposed or is there any reason for disallowing this. As ehcache code is implemented this way to throw NPE if the attribute value is null.

Code:
 public EqualTo(String attributeName, Object value) {
         if (value == null || attributeName == null) {
             throw new NullPointerException();
         }
 
         this.attributeName = attributeName;
         this.value = value;
 
         this.type = AttributeType.typeFor(attributeName, value);
     }
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team