<div dir="ltr">Hi Matej,<div><br></div><div>Thanks for the quick response.  I think you make a good point, and I have started the conversation with the Open Liberty web container developers to see what they think - but ultimately, I agree that it doesn&#39;t make much sense to destroy something that was never initialized. </div><div><br></div><div>That said, I don&#39;t think a null check would hurt anything - this would only occur on app shutdown, so performance shouldn&#39;t be a factor.  I&#39;ll leave it up to you.  The changes to how the startup exception is logged in Open Liberty fixes my primary concern (determining the original startup problem).</div><div><br></div><div>Thanks for considering!</div><div><br></div><div>Andy</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 9:08 AM Matej Novotny &lt;<a href="mailto:manovotn@redhat.com">manovotn@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
thanks for reporting this.<br>
<br>
I am not quite following how you manage to register a listener, *not* invoke contextInitialized but attempt to invoke contextDestroyed on it?<br>
Is the error happening during initialization of other listeners?<br>
To me it seems like Liberty shouldn&#39;t try to do that, e.g. only invoke contextDestroyed for listeners that had a chance to perform contextInitialized.<br>
I think I saw similar approach in Undertow (used in WFLY) but I am not sure from the top of my head.<br>
<br>
Adding null checks is also an option of course, but I kind of think this situation shouldn&#39;t really happen.<br>
I might be wrong, feel free to disagree :)<br>
<br>
Regards<br>
Matej<br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Andy McCright&quot; &lt;<a href="mailto:j.andrew.mccright@gmail.com" target="_blank">j.andrew.mccright@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
&gt; Sent: Wednesday, July 22, 2020 3:34:35 PM<br>
&gt; Subject: [weld-dev] NullPointer in WeldInitialListener<br>
&gt; <br>
&gt; Hi All,<br>
&gt; <br>
&gt; I&#39;m using Weld in Open Liberty and seeing a NullPointerException from<br>
&gt; WeldInitialListener when an app fails to start. The scenario goes something<br>
&gt; like this:<br>
&gt; 1) Server and app starts to start.<br>
&gt; 2) An error occurs in my app code throwing an uncaught exception.<br>
&gt; 3) Liberty&#39;s web container code then attempts to stop the<br>
&gt; still-not-yet-started app - this calls the WeldInitialListener&#39;s<br>
&gt; contextDestroyed method without ever calling the contextCreated method.<br>
&gt; 4) Because contextCreated was never called, there is a NullPointerException<br>
&gt; thrown from contextDestroyed (the lifecycle field is null), which ends up<br>
&gt; masking the root cause of the problem.<br>
&gt; <br>
&gt; I am in the process of fixing part of the problem (not logging the original<br>
&gt; exception) in Open Liberty issue 13124[1], but I wonder if we should also<br>
&gt; check if lifecycle is null in the contextDestroyed method[2] to avoid the<br>
&gt; NPE.<br>
&gt; <br>
&gt; Thanks,<br>
&gt; <br>
&gt; Andy<br>
&gt; <br>
&gt; [1] <a href="https://github.com/OpenLiberty/open-liberty/issues/13124" rel="noreferrer" target="_blank">https://github.com/OpenLiberty/open-liberty/issues/13124</a><br>
&gt; [2]<br>
&gt; <a href="https://github.com/weld/core/blob/2fe5d1f64c03b89cc562a14cda317098225590c7/modules/web/src/main/java/org/jboss/weld/module/web/servlet/WeldInitialListener.java#L113" rel="noreferrer" target="_blank">https://github.com/weld/core/blob/2fe5d1f64c03b89cc562a14cda317098225590c7/modules/web/src/main/java/org/jboss/weld/module/web/servlet/WeldInitialListener.java#L113</a><br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; weld-dev mailing list<br>
&gt; <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
<br>
</blockquote></div>