diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardWrapper.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardWrapper.java index b805357ba56..96711935d99 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardWrapper.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardWrapper.java @@ -55,7 +55,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Portions Copyright [2016-2019] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates] package org.apache.catalina.core; @@ -738,7 +738,7 @@ public Servlet getServlet() { * * @param instance the servlet instance */ - public void setServlet(Servlet instance) { + public synchronized void setServlet(Servlet instance) { if (instance == null) { throw new NullPointerException("Null servlet instance"); } @@ -1824,6 +1824,7 @@ public void unavailable(UnavailableException unavailable) { public synchronized void unload() throws ServletException { // Nothing to do if we have never loaded the instance + Servlet instance = this.instance; if (!singleThreadModel && instance == null) { return; } @@ -1871,7 +1872,7 @@ public synchronized void unload() throws ServletException { instanceSupport.fireInstanceEvent(AFTER_DESTROY_EVENT, instance); } catch (Throwable t) { instanceSupport.fireInstanceEvent(AFTER_DESTROY_EVENT, instance, t); - instance = null; + this.instance = null; instancePool = null; nInstances = 0; if (notifyContainerListeners) { @@ -1885,7 +1886,7 @@ public synchronized void unload() throws ServletException { } // Deregister the destroyed instance - instance = null; + this.instance = null; if (singleThreadModel && (instancePool != null)) { try {