Author: markt
Date: Tue Aug 23 16:47:40 2016
New Revision: 1757406
URL: http://svn.apache.org/viewvc?rev=1757406&view=rev
Log:
Improve handling of exceptions during a Lifecycle events triggered by a state
transition. The exception is now caught and the component is now placed into
the FAILED state.
Modified:
tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java?rev=1757406&r1=1757405&r2=1757406&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java Tue Aug 23
16:47:40 2016
@@ -101,18 +101,17 @@ public abstract class LifecycleBase impl
if (!state.equals(LifecycleState.NEW)) {
invalidTransition(Lifecycle.BEFORE_INIT_EVENT);
}
- setStateInternal(LifecycleState.INITIALIZING, null, false);
try {
+ setStateInternal(LifecycleState.INITIALIZING, null, false);
initInternal();
+ setStateInternal(LifecycleState.INITIALIZED, null, false);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
setStateInternal(LifecycleState.FAILED, null, false);
throw new LifecycleException(
sm.getString("lifecycleBase.initFail",toString()), t);
}
-
- setStateInternal(LifecycleState.INITIALIZED, null, false);
}
@@ -146,10 +145,20 @@ public abstract class LifecycleBase impl
invalidTransition(Lifecycle.BEFORE_START_EVENT);
}
- setStateInternal(LifecycleState.STARTING_PREP, null, false);
-
try {
+ setStateInternal(LifecycleState.STARTING_PREP, null, false);
startInternal();
+ if (state.equals(LifecycleState.FAILED)) {
+ // This is a 'controlled' failure. The component put itself
into the
+ // FAILED state so call stop() to complete the clean-up.
+ stop();
+ } else if (!state.equals(LifecycleState.STARTING)) {
+ // Shouldn't be necessary but acts as a check that sub-classes
are
+ // doing what they are supposed to.
+ invalidTransition(Lifecycle.AFTER_START_EVENT);
+ } else {
+ setStateInternal(LifecycleState.STARTED, null, false);
+ }
} catch (Throwable t) {
// This is an 'uncontrolled' failure so put the component into the
// FAILED state and throw an exception.
@@ -157,18 +166,6 @@ public abstract class LifecycleBase impl
setStateInternal(LifecycleState.FAILED, null, false);
throw new
LifecycleException(sm.getString("lifecycleBase.startFail", toString()), t);
}
-
- if (state.equals(LifecycleState.FAILED)) {
- // This is a 'controlled' failure. The component put itself into
the
- // FAILED state so call stop() to complete the clean-up.
- stop();
- } else if (!state.equals(LifecycleState.STARTING)) {
- // Shouldn't be necessary but acts as a check that sub-classes are
- // doing what they are supposed to.
- invalidTransition(Lifecycle.AFTER_START_EVENT);
- } else {
- setStateInternal(LifecycleState.STARTED, null, false);
- }
}
@@ -216,17 +213,25 @@ public abstract class LifecycleBase impl
invalidTransition(Lifecycle.BEFORE_STOP_EVENT);
}
- if (state.equals(LifecycleState.FAILED)) {
- // Don't transition to STOPPING_PREP as that would briefly mark the
- // component as available but do ensure the BEFORE_STOP_EVENT is
- // fired
- fireLifecycleEvent(BEFORE_STOP_EVENT, null);
- } else {
- setStateInternal(LifecycleState.STOPPING_PREP, null, false);
- }
-
try {
+ if (state.equals(LifecycleState.FAILED)) {
+ // Don't transition to STOPPING_PREP as that would briefly
mark the
+ // component as available but do ensure the BEFORE_STOP_EVENT
is
+ // fired
+ fireLifecycleEvent(BEFORE_STOP_EVENT, null);
+ } else {
+ setStateInternal(LifecycleState.STOPPING_PREP, null, false);
+ }
+
stopInternal();
+
+ // Shouldn't be necessary but acts as a check that sub-classes are
+ // doing what they are supposed to.
+ if (!state.equals(LifecycleState.STOPPING) &&
!state.equals(LifecycleState.FAILED)) {
+ invalidTransition(Lifecycle.AFTER_STOP_EVENT);
+ }
+
+ setStateInternal(LifecycleState.STOPPED, null, false);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
setStateInternal(LifecycleState.FAILED, null, false);
@@ -236,17 +241,8 @@ public abstract class LifecycleBase impl
// Complete stop process first
setStateInternal(LifecycleState.STOPPED, null, false);
destroy();
- return;
}
}
-
- // Shouldn't be necessary but acts as a check that sub-classes are
- // doing what they are supposed to.
- if (!state.equals(LifecycleState.STOPPING) &&
!state.equals(LifecycleState.FAILED)) {
- invalidTransition(Lifecycle.AFTER_STOP_EVENT);
- }
-
- setStateInternal(LifecycleState.STOPPED, null, false);
}
@@ -296,18 +292,16 @@ public abstract class LifecycleBase impl
invalidTransition(Lifecycle.BEFORE_DESTROY_EVENT);
}
- setStateInternal(LifecycleState.DESTROYING, null, false);
-
try {
+ setStateInternal(LifecycleState.DESTROYING, null, false);
destroyInternal();
+ setStateInternal(LifecycleState.DESTROYED, null, false);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
setStateInternal(LifecycleState.FAILED, null, false);
throw new LifecycleException(
sm.getString("lifecycleBase.destroyFail",toString()), t);
}
-
- setStateInternal(LifecycleState.DESTROYED, null, false);
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1757406&r1=1757405&r2=1757406&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Aug 23 16:47:40 2016
@@ -162,6 +162,11 @@
<bug>60008</bug>: When processing CORs requests, treat any origin with
a
URI scheme of <code>file</code> as a valid origin. (markt)
</fix>
+ <fix>
+ Improve handling of exceptions during a Lifecycle events triggered by a
+ state transition. The exception is now caught and the component is now
+ placed into the <code>FAILED</code> state. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]