jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject [jspwiki] 03/05: internal refactor: instead of catching EmptyStackException, check if the stack is empty or not
Date Sat, 03 Feb 2018 19:43:44 GMT
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit c877d1d432fe12a7d52c6c142c5fcd871733d193
Author: juanpablo <juanpablo@apache.org>
AuthorDate: Sat Feb 3 20:22:07 2018 +0100

    internal refactor: instead of catching EmptyStackException, check if the stack is empty
or not
---
 .../src/main/java/org/apache/wiki/WatchDog.java    | 25 ++++++++++------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/jspwiki-war/src/main/java/org/apache/wiki/WatchDog.java b/jspwiki-war/src/main/java/org/apache/wiki/WatchDog.java
index b50cc5d..94d236f 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/WatchDog.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/WatchDog.java
@@ -19,7 +19,6 @@
 package org.apache.wiki;
 
 import java.lang.ref.WeakReference;
-import java.util.EmptyStackException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
@@ -30,9 +29,8 @@ import org.apache.log4j.Logger;
 
 
 /**
- *  WatchDog is a general system watchdog.  You can attach any Watchable
- *  or a Thread object to it, and it will notify you if a timeout has been
- *  exceeded.
+ *  WatchDog is a general system watchdog.  You can attach any Watchable or a
+ *  Thread object to it, and it will notify you if a timeout has been exceeded.
  *  <p>
  *  The notification of the timeouts is done from a separate WatchDog thread,
  *  of which there is one per watched thread.  This Thread is named 'WatchDog for
@@ -68,8 +66,7 @@ public final class WatchDog {
      *  keeps an internal list of Watchdogs for you so that there
      *  won't be more than one watchdog per thread.
      *
-     *  @param engine The WikiEngine to which the Watchdog should
-     *                be bonded to.
+     *  @param engine The WikiEngine to which the Watchdog should be bonded to.
      *  @return A usable WatchDog object.
      */
     public static WatchDog getCurrentWatchDog( WikiEngine engine ) {
@@ -227,7 +224,7 @@ public final class WatchDog {
      *  @param state The state you wish to exit.
      */
     public void exitState( String state ) {
-        try {
+        if( !m_stateStack.empty() ) {
             synchronized( m_stateStack ) {
                 State st = m_stateStack.peek();
                 if( state == null || st.getState().equals( state ) ) {
@@ -241,8 +238,8 @@ public final class WatchDog {
                     log.error( "exitState() called before enterState()" );
                 }
             }
-        } catch( EmptyStackException e ) {
-            log.error( "Stack for " + m_watchable.getName() + " is empty!", e );
+        } else {
+            log.warn( "Stack for " + m_watchable.getName() + " is empty!" );
         }
     }
 
@@ -270,7 +267,7 @@ public final class WatchDog {
         }
 
         synchronized( m_stateStack ) {
-            try {
+            if( !m_stateStack.empty() ) {
                 State st = m_stateStack.peek();
                 long now = System.currentTimeMillis();
 
@@ -282,8 +279,8 @@ public final class WatchDog {
 
                     m_watchable.timeoutExceeded(st.getState());
                 }
-            } catch( EmptyStackException e ) {
-            	log.error( "Stack for " + m_watchable.getName() + " is empty!", e );
+            } else {
+            	log.warn( "Stack for " + m_watchable.getName() + " is empty!" );
             }
         }
     }
@@ -328,10 +325,10 @@ public final class WatchDog {
         synchronized( m_stateStack ) {
             String state = "Idle";
 
-            try {
+            if( !m_stateStack.empty() ) {
                 State st = m_stateStack.peek();
                 state = st.getState();
-            } catch( EmptyStackException e ) {}
+            }
             return "WatchDog state=" + state;
         }
     }

-- 
To stop receiving notification emails like this one, please contact
juanpablo@apache.org.

Mime
View raw message