<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jbrisbin" rel="nofollow">Jon Brisbin</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8201?redirect=false" rel="nofollow">SPR-8201</a></strong> and commented</p>
<p dir="auto">The ApplicationEvent dispatcher should take generics information into account when deciding whether to call a particular <code class="notranslate">ApplicationListener</code>. This would allow the user to register an <code class="notranslate">ApplicationListener</code> for their event subclass like this:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public class BeforeSaveEvent&lt;T&gt; extends ApplicationEvent {}
public class MyListener implements ApplicationListener&lt;BeforeSaveEvent&lt;MyDomainObject&gt;&gt;{}"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">BeforeSaveEvent</span>&lt;<span class="pl-smi">T</span>&gt; <span class="pl-k">extends</span> <span class="pl-smi">ApplicationEvent</span> {}
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">MyListener</span> <span class="pl-k">implements</span> <span class="pl-smi">ApplicationListener</span>&lt;<span class="pl-smi">BeforeSaveEvent</span>&lt;<span class="pl-smi">MyDomainObject</span>&gt;&gt;{}</pre></div>
<p dir="auto">When a <code class="notranslate">BeforeSaveEvent&lt;MyDomainObject&gt;</code> event is dispatched, only those <code class="notranslate">ApplicationListener</code> that have specified <code class="notranslate">MyDomainObject</code> in the generics clause will be dispatched to the configured listener (such as <code class="notranslate">MyListener</code>)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</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="398163801" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/15847" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/15847/hovercard" href="https://github.com/spring-projects/spring-framework/issues/15847">#15847</a> improve ApplicationListener to support generic types (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">2 votes, 6 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jmather" rel="nofollow">Julie Mather</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4174?redirect=false" rel="nofollow">SPR-4174</a></strong> and commented</p>
<p dir="auto">If you look at the MailSendException class' printStackTrace methods, note the first line:<br>
if (this.messageExceptions.length == 0) {</p>
<p dir="auto">The messageExceptions variable is only not null if you call the MailSendException(Map failedMessages) constructor. The other two constructors do not initialize the messageExceptions variable to a value and thus when printStackTrace is called a NullPointerException is thrown. Our code (and one of our unit tests that exposed this to me) calls:<br>
throw new MailSendException("boom");<br>
And thus breaks.</p>
<p dir="auto">It's really as simple as not referencing messageExceptions directly but using the getter instead, which is what it's there for.... It has a null check in it and will return an empty array if the variable hasn't been initialized yet. Nicely done, it's just not being used.</p>
<p dir="auto">And by the way, that you very much for 2.5. It was quite easy to migrate to.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5 final</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="398082894" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8817" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8817/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8817">#8817</a> NullPointerException in MailSendException (<em><strong>"duplicates"</strong></em>)</li>
</ul>