Skip to content

Commit 86ac32f

Browse files
authored
Merge pull request #481 from francescomari/fix/whiteboard-manager-shutdown-npe
Fix unrecoverable Jetty state after NPE in WhiteboardManager shutdown
2 parents 5d90911 + 00e2640 commit 86ac32f

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ public void stop()
199199
this.serviceRuntime.unregister();
200200
for(final ServiceTracker<?, ?> t : this.trackers)
201201
{
202-
t.close();
202+
try
203+
{
204+
t.close();
205+
}
206+
catch (final Exception e)
207+
{
208+
SystemLogger.LOGGER.error("Exception while closing service tracker", e);
209+
}
203210
}
204211
this.trackers.clear();
205212
this.preprocessorHandlers = Collections.emptyList();
@@ -328,7 +335,10 @@ private void deactivate(final WhiteboardContextHandler handler)
328335
}
329336
}
330337
// context listeners last
331-
handler.getRegistry().getEventListenerRegistry().contextDestroyed();
338+
if ( handler.getRegistry() != null )
339+
{
340+
handler.getRegistry().getEventListenerRegistry().contextDestroyed();
341+
}
332342
for(final WhiteboardServiceInfo<?> info : listeners)
333343
{
334344
this.unregisterWhiteboardService(handler, info);
@@ -480,6 +490,10 @@ else if ( activateNext )
480490
this.failureStateHandler.addFailure(newHead.getContextInfo(), DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE);
481491
}
482492
}
493+
if ( handlerList.isEmpty() )
494+
{
495+
this.contextMap.remove(info.getName());
496+
}
483497
}
484498
}
485499
}
@@ -494,6 +508,10 @@ else if ( activateNext )
494508
private List<WhiteboardContextHandler> getMatchingContexts(final WhiteboardServiceInfo<?> info) {
495509
final List<WhiteboardContextHandler> result = new ArrayList<>();
496510
for(final List<WhiteboardContextHandler> handlerList : this.contextMap.values()) {
511+
if ( handlerList.isEmpty() )
512+
{
513+
continue;
514+
}
497515
final WhiteboardContextHandler h = handlerList.get(0);
498516

499517
// check if the context matches
@@ -881,6 +899,10 @@ private WhiteboardContextHandler getContextHandler(final String name)
881899
{
882900
for(final List<WhiteboardContextHandler> handlerList : this.contextMap.values())
883901
{
902+
if ( handlerList.isEmpty() )
903+
{
904+
continue;
905+
}
884906
final WhiteboardContextHandler h = handlerList.get(0);
885907
if ( h.getContextInfo().getName().equals(name) )
886908
{

http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,14 @@ private void stopJetty()
215215
if (this.server != null)
216216
{
217217
this.controller.getEventDispatcher().setActive(false);
218-
this.controller.unregister();
218+
try
219+
{
220+
this.controller.unregister();
221+
}
222+
catch (final Exception e)
223+
{
224+
SystemLogger.LOGGER.error("Exception during controller unregister", e);
225+
}
219226

220227
if (this.fileRequestLog != null)
221228
{

http/jetty12/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ private void stopJetty()
225225
if (this.server != null)
226226
{
227227
this.controller.getEventDispatcher().setActive(false);
228-
this.controller.unregister();
228+
try
229+
{
230+
this.controller.unregister();
231+
}
232+
catch (final Exception e)
233+
{
234+
SystemLogger.LOGGER.error("Exception during controller unregister", e);
235+
}
229236

230237
if (this.fileRequestLog != null)
231238
{

0 commit comments

Comments
 (0)