qianjava / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 0 forks source link

@Cacheable(cacheName="name", selfPopulating = true) throws NullPointerException instead of initial cause of exception #79

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Annotate a service method with @Cacheable(cacheName="name", selfPopulating = 
true)
2. In the body of the annotated method throw an exception
3. Call the service method from another bean

What is the expected output? What do you see instead?
I would expect to see the initial exception but instead I see 
NullPointerException

What version of the product are you using? On what operating system?
1.1.3, windows 7 (64 bit)

Please provide any additional information below.
After debugging I found that in 
EhCacheInterceptor.invokeSelftPopulatingCacheable(..) method:
        try {
            element = cache.get(key);
        }
        catch (Throwable t) {
            Throwable cause = t.getCause();
            this.cacheException(cacheableAttribute, methodInvocation, key, cause);
            throw cause;
        }

the t.getCause() is null all the time instead of returning the cause of the 
exception.

I think it's because of the CacheException implementation that instead of using 
super(message, initialCause) is using super(message), see below:
public CacheException(String message, Throwable initialCause) {
        super(message);
        this.initialCause = initialCause;
    }

Therefore t.getCause() returns null;

Original issue reported on code.google.com by agladkow...@gmail.com on 9 Aug 2011 at 10:48

GoogleCodeExporter commented 8 years ago
Can you please provide a complete stack trace.

Original comment by eric.dalquist on 9 Aug 2011 at 1:06

GoogleCodeExporter commented 8 years ago
I am having a problem with re-creating this issue.
I was running junit test for a service annotated with @Cacheable in Eclipse 
using eclEmma plugin.
After refreshing and cleaning up workspace the problem disappeared.

I'll update the issue as soon as I hit the problem again.

Original comment by agladkow...@gmail.com on 9 Aug 2011 at 1:20

GoogleCodeExporter commented 8 years ago
What version of Ehcache are you using?

Original comment by eric.dalquist on 15 Aug 2011 at 3:26

GoogleCodeExporter commented 8 years ago
It looks like in some versions of EhCache the cause can be null. I've changed 
the logic to use the original Throwable if getCause returns null.

Original comment by eric.dalquist on 15 Aug 2011 at 5:25

GoogleCodeExporter commented 8 years ago
I am using ehcache 2.2.0

Original comment by agladkow...@gmail.com on 15 Aug 2011 at 6:33

GoogleCodeExporter commented 8 years ago

Original comment by eric.dalquist on 15 Aug 2011 at 6:59

GoogleCodeExporter commented 8 years ago

Original comment by eric.dalquist on 15 Aug 2011 at 7:00

GoogleCodeExporter commented 8 years ago
Eric,
Is there any chance for getting the package with the fix for the problem above?

Please advice.

~Andrzej

Original comment by agladkow...@gmail.com on 19 Aug 2011 at 3:18

GoogleCodeExporter commented 8 years ago
Ah sure. I can look at getting a release cut next week. Which version are you 
using right now?

Original comment by eric.dalquist on 19 Aug 2011 at 3:20

GoogleCodeExporter commented 8 years ago
I am using version 1.1.3

Thanks a lot Eric!

~Andrzej

On Fri, Aug 19, 2011 at 4:21 PM,
<ehcache-spring-annotations@googlecode.com>wrote:

Original comment by agladkow...@gmail.com on 19 Aug 2011 at 3:42

GoogleCodeExporter commented 8 years ago
Hi Eric,
I saw that a new version was released 1.2.0. Unfortunately the code still
behavies the same.
The client alwasy gets NPE (instead of business exception) when calls method
annotated withch @cacheable that throws business exception.

It's a problem in EhCacheInterceptor.java, line 164.
164            Throwable cause = t.getCause(); (this returns null, it's
always CacheException that do not have cause, the cause is actually stored
in initialCause field)
165           this.cacheException(cacheableAttribute, methodInvocation, key,
cause); (in here is cause is null we should add 't' instead and the problem
should be fixed)
166           throw cause;

Please let me know if you can make this change.

Thanks a lot,
Andrzej

On Fri, Aug 19, 2011 at 4:42 PM, Andrzej Gladkowski
<agladkowski@gmail.com>wrote:

Original comment by agladkow...@gmail.com on 23 Sep 2011 at 8:49

GoogleCodeExporter commented 8 years ago
EhcacheInterceptor.java line 164 is a comment in the 1.2.0 release: 
http://code.google.com/p/ehcache-spring-annotations/source/browse/tags/ehcache-s
pring-annotations-1.2.0/core/src/main/java/com/googlecode/ehcache/annotations/in
terceptor/EhCacheInterceptor.java#164

Also net.sf.ehcache.CacheException has correctly populated the field that backs 
getCause() for quite a while.

What version of ehcache are you using and are you sure you have the latest 
ehcache-spring-annotations deployed with no conflicting versions?

Original comment by eric.dalquist on 23 Sep 2011 at 12:43

GoogleCodeExporter commented 8 years ago
I upgraded to ehcache-spring-annotations 1.2.0 and ehcache-core 2.4.5 I also
removed all ehcache transitive dependencies from my pom.xml

It all works when I run tests using mvn command but it fails in Eclipse IDE
for some reason throwing NPE.

Thanks Eric

On Fri, Sep 23, 2011 at 1:44 PM,
<ehcache-spring-annotations@googlecode.com>wrote:

Original comment by agladkow...@gmail.com on 23 Sep 2011 at 2:53

GoogleCodeExporter commented 8 years ago
Weird, sounds like Eclipse is pulling in some old/incorrect dependency.

Original comment by eric.dalquist on 23 Sep 2011 at 4:22