Skip to content

Commit

Permalink
fixed undeployment race condition NPE (#5156)
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak authored Mar 10, 2021
1 parent 2135500 commit e7d6c2b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -1885,7 +1886,7 @@ public synchronized void unload() throws ServletException {
}

// Deregister the destroyed instance
instance = null;
this.instance = null;

if (singleThreadModel && (instancePool != null)) {
try {
Expand Down

0 comments on commit e7d6c2b

Please sign in to comment.