<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't make much sense to destroy something that was never initialized. </div><div><br></div><div>That said, I don't think a null check would hurt anything - this would only occur on app shutdown, so performance shouldn't be a factor. I'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 <<a href="mailto:manovotn@redhat.com">manovotn@redhat.com</a>> 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'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't really happen.<br>
I might be wrong, feel free to disagree :)<br>
<br>
Regards<br>
Matej<br>
<br>
----- Original Message -----<br>
> From: "Andy McCright" <<a href="mailto:j.andrew.mccright@gmail.com" target="_blank">j.andrew.mccright@gmail.com</a>><br>
> To: <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
> Sent: Wednesday, July 22, 2020 3:34:35 PM<br>
> Subject: [weld-dev] NullPointer in WeldInitialListener<br>
> <br>
> Hi All,<br>
> <br>
> I'm using Weld in Open Liberty and seeing a NullPointerException from<br>
> WeldInitialListener when an app fails to start. The scenario goes something<br>
> like this:<br>
> 1) Server and app starts to start.<br>
> 2) An error occurs in my app code throwing an uncaught exception.<br>
> 3) Liberty's web container code then attempts to stop the<br>
> still-not-yet-started app - this calls the WeldInitialListener's<br>
> contextDestroyed method without ever calling the contextCreated method.<br>
> 4) Because contextCreated was never called, there is a NullPointerException<br>
> thrown from contextDestroyed (the lifecycle field is null), which ends up<br>
> masking the root cause of the problem.<br>
> <br>
> I am in the process of fixing part of the problem (not logging the original<br>
> exception) in Open Liberty issue 13124[1], but I wonder if we should also<br>
> check if lifecycle is null in the contextDestroyed method[2] to avoid the<br>
> NPE.<br>
> <br>
> Thanks,<br>
> <br>
> Andy<br>
> <br>
> [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>
> [2]<br>
> <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>
> <br>
> <br>
> <br>
> _______________________________________________<br>
> weld-dev mailing list<br>
> <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
> <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>