<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=michal.troicki" rel="nofollow">Michal Troicki</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9364?redirect=false" rel="nofollow">SPR-9364</a></strong> and commented</p>
<p dir="auto">If ReflectionUtils.findMethod return null we should return true instead invocation of the method fail with NullPointerException.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="protected boolean determineRequiredStatus(Annotation annotation) {
		try {
			Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName);
			return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation));
		}
		catch (Exception ex) {
			// required by default
			return true;
		}
	}"><pre class="notranslate"><code class="notranslate">protected boolean determineRequiredStatus(Annotation annotation) {
		try {
			Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName);
			return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation));
		}
		catch (Exception ex) {
			// required by default
			return true;
		}
	}
</code></pre></div>
<hr>
<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="398118599" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13954" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13954/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13954">#13954</a> caught NullPointerException in AutowiredAnnotationBeanPostProcessor.determineRequiredStatus (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=marschall" rel="nofollow">Philippe Marschall</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9316?redirect=false" rel="nofollow">SPR-9316</a></strong> and commented</p>
<p dir="auto">AutowiredAnnotationBeanPostProcessor.determineRequiredStatus uses ReflectionUtils.findMethod to look up a method named "required". If there is no such method then ReflectionUtils.findMethod returns null. However AutowiredAnnotationBeanPostProcessor.determineRequiredStatus never checks for null instead it directly passes the method to ReflectionUtils.invokeMethod which throws a NullPointerException which is then caught in a catch (Exception ex) block in AutowiredAnnotationBeanPostProcessor.determineRequiredStatus.</p>
<p dir="auto">Annoations that don't have a method named "required" include <code class="notranslate">@Inject</code> <code class="notranslate">@Value</code> <code class="notranslate">@Resource</code>.</p>
<p dir="auto">This is not so nice for several reasons:</p>
<ul dir="auto">
<li>when you debug one of your own NullPointerExceptions and set an exception breakpoint on NullPointerException you end up in Spring code</li>
<li>it uses NullPointerExceptions and catching them as part of normal control flow</li>
<li>filling in the stack trace of an exception is slow</li>
</ul>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</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="398118871" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14001" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14001/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14001">#14001</a> AutowiredAnnotationBeanPostProcessor.determineRequiredStatus(Annotation) throws NullPointerException if method wasnt found. (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/26ee0c4842ca83dec213b5422d0af18ba2e3ce6c/hovercard" href="https://github.com/spring-projects/spring-framework/commit/26ee0c4842ca83dec213b5422d0af18ba2e3ce6c"><tt>26ee0c4</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/2624b909060e0967e16771de7a35261decd5a4a9/hovercard" href="https://github.com/spring-projects/spring-framework/commit/2624b909060e0967e16771de7a35261decd5a4a9"><tt>2624b90</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/46bdb2de077063663f0daae85431ebe5c430edc8/hovercard" href="https://github.com/spring-projects/spring-framework/commit/46bdb2de077063663f0daae85431ebe5c430edc8"><tt>46bdb2d</tt></a></p>