From bb705db4046803861cf5146d8d414b34bde65ed2 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Thu, 27 Sep 2018 14:27:12 +0530 Subject: [PATCH] PAYARA-3119 NullPointerException when starting Jersey/EJB Containers in Order --- .../com/sun/ejb/containers/BaseContainer.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java index 8ad2e49bd40..803e92b898a 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java @@ -512,6 +512,8 @@ public enum ContainerType { protected InterceptorManager interceptorManager; + private Set pendingInterceptors = new HashSet<>(); + // the order must be the same as CallbackType and getPre30LifecycleMethodNames private static final Class[] lifecycleCallbackAnnotationClasses = { AroundConstruct.class, @@ -3446,16 +3448,25 @@ protected String[] getPre30LifecycleMethodNames() { }; }; - private void initializeInterceptorManager() throws Exception { + private synchronized void initializeInterceptorManager() throws Exception { this.interceptorManager = new InterceptorManager(_logger, this, lifecycleCallbackAnnotationClasses, getPre30LifecycleMethodNames()); + if (!pendingInterceptors.isEmpty()) { + pendingInterceptors.forEach(this::registerSystemInterceptor); + pendingInterceptors.clear(); + } } - void registerSystemInterceptor(Object o) { - + void registerSystemInterceptor(Object interceptor) { if (needSystemInterceptorProxy()) { - interceptorManager.registerRuntimeInterceptor(o); + synchronized (this) { + if (interceptorManager == null) { + pendingInterceptors.add(interceptor); + } else { + interceptorManager.registerRuntimeInterceptor(interceptor); + } + } } }