<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=washley" rel="nofollow">William Ashley</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5959?redirect=false" rel="nofollow">SPR-5959</a></strong> and commented</p>
<p dir="auto">Here is a condensed example of the problem I'm encountering:</p>
<p dir="auto">Controller:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package com.test;

import java.io.PrintWriter;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Transactional( readOnly=true )
public class Test
{
	@ExceptionHandler
	public void exception( Throwable t )
	{
		System.out.println( &quot;In exception handler&quot; );
	}
	
	@RequestMapping( &quot;/&quot; )
	public void get()
	{
		throw new RuntimeException( &quot;foo&quot; );
	}
}"><pre class="notranslate"><code class="notranslate">package com.test;

import java.io.PrintWriter;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Transactional( readOnly=true )
public class Test
{
	@ExceptionHandler
	public void exception( Throwable t )
	{
		System.out.println( "In exception handler" );
	}
	
	@RequestMapping( "/" )
	public void get()
	{
		throw new RuntimeException( "foo" );
	}
}
</code></pre></div>
<p dir="auto">Dispatcher servlet config:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;&gt;
	
	&lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot;/&gt;
	&lt;bean id=&quot;transactionManager&quot; class=&quot;com.test.MockTransactionManager&quot;/&gt;
	
	&lt;context:component-scan base-package=&quot;com.test&quot;/&gt;
	
&lt;/beans&gt;"><pre class="notranslate"><code class="notranslate">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
	
	&lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
	&lt;bean id="transactionManager" class="com.test.MockTransactionManager"/&gt;
	
	&lt;context:component-scan base-package="com.test"/&gt;
	
&lt;/beans&gt;
</code></pre></div>
<p dir="auto">web.xml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd&quot;
	version=&quot;2.5&quot;&gt;
	
	&lt;servlet&gt;
		&lt;servlet-name&gt;action&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;action&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	
&lt;/web-app&gt;"><pre class="notranslate"><code class="notranslate">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
	version="2.5"&gt;
	
	&lt;servlet&gt;
		&lt;servlet-name&gt;action&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;action&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	
&lt;/web-app&gt;
</code></pre></div>
<p dir="auto">The exception handler is never invoked when the controller is proxied by CGLib (removing <code class="notranslate">@Transactional</code> removes the proxy and restores the exception handler). A little digging led me to org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver  where there is this iteration over methods of the controller</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="		ReflectionUtils.doWithMethods(handlerType, new ReflectionUtils.MethodCallback() {
			public void doWith(Method method) {
				method = ClassUtils.getMostSpecificMethod(method, handlerType);
[snip]
			}
		});"><pre class="notranslate"><code class="notranslate">		ReflectionUtils.doWithMethods(handlerType, new ReflectionUtils.MethodCallback() {
			public void doWith(Method method) {
				method = ClassUtils.getMostSpecificMethod(method, handlerType);
[snip]
			}
		});
</code></pre></div>
<p dir="auto">which does arrive eventually at the proper exception handler method of my controller class, but because of the call to ClassUtils.getMostSpecificMethod() it winds up back at the overridden method on the CGLib-generated class (which from what I noticed it had already visited). I haven't researched enough to say this is the problem though.</p>
<p dir="auto"><code class="notranslate">@RequestMapping</code> annotations appear to work normally through a proxied controller (and the <code class="notranslate">@Transactional</code> annotation does function correctly), so I'm hoping this can be fixed.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 M3</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398097379" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10761" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10761/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10761">#10761</a> MVC Annotation Inheritance (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398106011" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11996" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11996/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11996">#11996</a> <code class="notranslate">@ExceptionHandler</code> doesn't work on CGLib-proxied controller in Portlet MVC</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=chrislee" rel="nofollow">Chris Lee</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2413?redirect=false" rel="nofollow">SPR-2413</a></strong> and commented</p>
<p dir="auto">Upgrading from 2.0RC2 to 2.0RC3; aside from a couple of moved classes, everything went smooth, until we turned on DEBUG for org.springframework.</p>
<p dir="auto">This resulting in a NPE:</p>
<p dir="auto">java.lang.NullPointerException<br>
at org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor$TransactionAttributeSourcePointcut.getTransactionAttributeSource(TransactionAttributeSourceAdvisor.java:102)<br>
at org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor$TransactionAttributeSourcePointcut.hashCode(TransactionAttributeSourceAdvisor.java:121)<br>
at java.lang.Object.toString(Object.java:209)<br>
at java.lang.String.valueOf(String.java:2615)<br>
at java.lang.StringBuffer.append(StringBuffer.java:220)<br>
at org.springframework.aop.support.AbstractPointcutAdvisor.toString(AbstractPointcutAdvisor.java:71)<br>
at java.lang.String.valueOf(String.java:2615)<br>
at java.lang.StringBuffer.append(StringBuffer.java:220)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:383)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:242)</p>
<p dir="auto">...the bean that triggered this was:</p>
<p dir="auto">&lt;bean id="apTransactionAttributeSourceAdvisor"<br>
class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt;<br>
&lt;property name="transactionInterceptor" ref="apTxInterceptor" /&gt;<br>
&lt;property name="classFilter"&gt;<br>
&lt;bean class="org.springframework.aop.aspectj.TypePatternClassFilter"&gt;<br>
&lt;property name="typePattern" value="bridges.authPortal..*" /&gt;<br>
&lt;/bean&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">It looks like AbstractAutowireCapableBeanFactory logs a debug message (line 383) "Eagerly caching...", which forces a toString on the instantiated bean; since the TransactionAttributeSourceAdvisor.TransactionAttributeSourcePointcut does not have a toString() method, it uses Object.toString, which calls hashCode(), triggering the NPE (as the interceptor hasn't been injected yet).</p>
<p dir="auto">Possible solutions are to remove the hashCode (presumably it is there for a reason though) or add a toString() method to TransactionAttributeSourceAdvisor.TransactionAttributeSourcePointcut</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC3</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398070047" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7192" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7192/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7192">#7192</a> Change of logging level to debug causes bean creation failure in presence of tx:annotation-driven (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398069278" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7103" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7103/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7103">#7103</a> NPE when creating a TransactionAttributeSourceAdvisor bean w/debug enabled (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398070130" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7205" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7205/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7205">#7205</a> Bug with tx:annotation-driven/ and JPA with Spring 2 RC3: internal creation TransactionAttributeSourceAdvisor leads to NPE (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398070718" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7277" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7277/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7277">#7277</a> Turning on debugging causes NPE with aspects (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>