[jsword-svn] r1150 - in trunk/common/src: main/java/org/crosswire/common/activate main/java/org/crosswire/common/config main/java/org/crosswire/common/progress main/java/org/crosswire/common/util main/java/org/crosswire/common/xml test/java/org/crosswire/common/util

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Tue Oct 10 16:29:09 MST 2006


Author: dmsmith
Date: 2006-10-10 16:28:31 -0700 (Tue, 10 Oct 2006)
New Revision: 1150

Removed:
   trunk/common/src/main/java/org/crosswire/common/util/ThreadUtil.java
   trunk/common/src/test/java/org/crosswire/common/util/ThreadUtilTest.java
Modified:
   trunk/common/src/main/java/org/crosswire/common/activate/Activator.java
   trunk/common/src/main/java/org/crosswire/common/activate/Kill.java
   trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java
   trunk/common/src/main/java/org/crosswire/common/config/Choice.java
   trunk/common/src/main/java/org/crosswire/common/config/Config.java
   trunk/common/src/main/java/org/crosswire/common/progress/Job.java
   trunk/common/src/main/java/org/crosswire/common/util/CWClassLoader.java
   trunk/common/src/main/java/org/crosswire/common/util/CallContext.java
   trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/Convert.java
   trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java
   trunk/common/src/main/java/org/crosswire/common/util/LucidRuntimeException.java
   trunk/common/src/main/java/org/crosswire/common/util/PatternFormatter.java
   trunk/common/src/main/java/org/crosswire/common/util/Reporter.java
   trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/StackTrace.java
   trunk/common/src/main/java/org/crosswire/common/util/WebResource.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLFeature.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java
   trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java
   trunk/common/src/test/java/org/crosswire/common/util/AllTests.java
Log:
Fixing bugs reported by findbugs.

Modified: trunk/common/src/main/java/org/crosswire/common/activate/Activator.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/activate/Activator.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/activate/Activator.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -22,6 +22,7 @@
 package org.crosswire.common.activate;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
 /**
@@ -83,10 +84,19 @@
         }
     }
 
+    public static void deactivateAll()
+    {
+        Iterator iter = activated.iterator();
+        while (iter.hasNext())
+        {
+            deactivate((Activatable) iter.next());
+        }
+    }
+
     /**
      * The list of things that we have activated
      */
-    protected static Set activated = new HashSet();
+    private static Set activated = new HashSet();
 
     /**
      * The object we use to prevent others from

Modified: trunk/common/src/main/java/org/crosswire/common/activate/Kill.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/activate/Kill.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/activate/Kill.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -21,8 +21,6 @@
  */
 package org.crosswire.common.activate;
 
-import java.util.Iterator;
-
 /**
  * Enumeration of how memory is returned.
  *
@@ -38,11 +36,7 @@
         /* @Override */
         public void reduceMemoryUsage()
         {
-            Iterator iter = Activator.activated.iterator();
-            while (iter.hasNext())
-            {
-                Activator.deactivate((Activatable) iter.next());
-            }
+            Activator.deactivateAll();
         }
     };
 

Modified: trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -101,7 +101,7 @@
             {
                 getter = clazz.getMethod("get" + propertyname, new Class[0]); //$NON-NLS-1$
             }
-            catch (Exception ex)
+            catch (NoSuchMethodException e)
             {
                 getter = clazz.getMethod("is" + propertyname, new Class[0]); //$NON-NLS-1$
             }
@@ -242,32 +242,36 @@
     /* (non-Javadoc)
      * @see org.crosswire.common.config.Choice#setString(java.lang.String)
      */
-    public void setString(String value) throws Exception
+    public void setString(String value) throws ConfigException
     {
+        Exception ex = null;
         try
         {
             Object object = convertToObject(value);
             setter.invoke(null, new Object[] { object });
         }
-        catch (InvocationTargetException ex)
+        catch (InvocationTargetException e)
         {
+            ex = e;
+        }
+        catch (IllegalArgumentException e)
+        {
+            ex = e;
+        }
+        catch (IllegalAccessException e)
+        {
+            ex = e;
+        }
+
+        if (ex != null)
+        {
             log.info("Exception while attempting to execute: " + setter.toString()); //$NON-NLS-1$
 
-            Throwable orig = ex.getTargetException();
-            if (orig instanceof Exception)
-            {
-                throw (Exception) orig;
-            }
 
             // So we can't re-throw the original exception because it wasn't an
             // Exception so we will have to re-throw the InvocationTargetException
-            throw ex;
+            throw new ConfigException(Msg.CONFIG_SETFAIL, ex, new Object[] { setter });
         }
-        catch (Exception ex)
-        {
-            log.info("Exception while attempting to execute: " + setter.toString()); //$NON-NLS-1$
-            throw ex;
-        }
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/config/Choice.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Choice.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/config/Choice.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -83,7 +83,7 @@
      * point. The Config dialog ought to cope with any errors.
      * @param value The new value for this Choice
      */
-    void setString(String value) throws Exception;
+    void setString(String value) throws ConfigException;
 
     /**
      * Gets a brief description of what is going on

Modified: trunk/common/src/main/java/org/crosswire/common/config/Config.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Config.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/config/Config.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -33,6 +33,7 @@
 
 import org.crosswire.common.util.EventListenerList;
 import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.LucidException;
 import org.crosswire.common.util.Reporter;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -130,13 +131,31 @@
             Element element = (Element) iter.next();
             String key = element.getAttributeValue("key"); //$NON-NLS-1$
 
+            Exception ex = null;
             try
             {
                 Choice choice = ChoiceFactory.getChoice(element, configResources);
                 add(key, choice);
             }
-            catch (Exception ex)
+            catch (StartupException e)
             {
+                ex = e;
+            }
+            catch (ClassNotFoundException e)
+            {
+                ex = e;
+            }
+            catch (IllegalAccessException e)
+            {
+                ex = e;
+            }
+            catch (InstantiationException e)
+            {
+                ex = e;
+            }
+
+            if (ex != null)
+            {
                 log.warn("Error creating config element, key=" + key, ex); //$NON-NLS-1$
             }
         }
@@ -144,6 +163,7 @@
 
     /**
      * Remove a key/model pairing
+     * 
      * @param key The name to kill
      */
     public void remove(String key)
@@ -245,17 +265,9 @@
         while (iter.hasNext())
         {
             String key = (String) iter.next();
-            try
-            {
-                Choice model = getChoice(key);
-                String value = model.getString();
-                local.put(key, value);
-            }
-            catch (Exception ex)
-            {
-                log.warn("Failure with setting " + key); //$NON-NLS-1$
-                Reporter.informUser(this, ex);
-            }
+            Choice model = getChoice(key);
+            String value = model.getString();
+            local.put(key, value);
         }
     }
 
@@ -286,22 +298,22 @@
                 newValue = oldValue;
             }
 
-            try
+            // If a value has not changed, we only call setString()
+            // if force==true or if a higher priority choice has
+            // changed.
+            if (!newValue.equals(oldValue))
             {
-                // If a value has not changed, we only call setString()
-                // if force==true or if a higher priority choice has
-                // changed.
-                if (!newValue.equals(oldValue))
+                log.info("Setting " + key + "=" + newValue + " (was " + oldValue + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                try
                 {
-                    log.info("Setting " + key + "=" + newValue + " (was " + oldValue + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                     choice.setString(newValue);
                 }
+                catch (LucidException ex)
+                {
+                    log.warn("Failure setting " + key + "=" + newValue, ex);  //$NON-NLS-1$ //$NON-NLS-2$
+                    Reporter.informUser(this, new ConfigException(Msg.CONFIG_SETFAIL, ex, new Object[] { choice.getFullPath() }));
+                }
             }
-            catch (Exception ex)
-            {
-                log.warn("Failure setting " + key + "=" + newValue, ex);  //$NON-NLS-1$ //$NON-NLS-2$
-                Reporter.informUser(this, new ConfigException(Msg.CONFIG_SETFAIL, ex, new Object[] { choice.getFullPath() }));
-            }
         }
 //        int highestChange = Choice.PRIORITY_LOWEST;
 //

Modified: trunk/common/src/main/java/org/crosswire/common/progress/Job.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -288,18 +288,18 @@
         final List temp = new ArrayList();
         synchronized (this)
         {
-            temp.addAll(listeners);
+            if (listeners != null)
+            {
+                temp.addAll(listeners);
+            }
         }
 
         // We ought only to tell listeners about jobs that are in our
         // list of jobs so we need to fire before delete.
-        if (listeners != null)
+        int count = temp.size();
+        for (int i = 0; i < count; i++)
         {
-            int count = temp.size();
-            for (int i = 0; i < count; i++)
-            {
-                ((WorkListener) temp.get(i)).workStateChanged(ev);
-            }
+            ((WorkListener) temp.get(i)).workStateChanged(ev);
         }
     }
 

Modified: trunk/common/src/main/java/org/crosswire/common/util/CWClassLoader.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/CWClassLoader.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/CWClassLoader.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -55,7 +55,7 @@
      */
     public CWClassLoader()
     {
-        owner = CallContext.instance().getCallingClass();
+        owner = CallContext.getCallingClass();
     }
 
     /* (non-Javadoc)

Modified: trunk/common/src/main/java/org/crosswire/common/util/CallContext.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/CallContext.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/CallContext.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -74,7 +74,7 @@
      * When called from a method it will return the class
      * calling that method.
       */
-    public Class getCallingClass()
+    public static Class getCallingClass()
     {
         return getCallingClass(1); // add 1 for this method
     }
@@ -86,9 +86,9 @@
      * -2 and -3 will return this class
      * @throws ArrayIndexOutOfBoundsException if the index is not valid
      */
-    public Class getCallingClass(int i)
+    public static Class getCallingClass(int i)
     {
-        return resolver.getClassContext()[CALL_CONTEXT_OFFSET + i];
+        return instance().getClassContext()[CALL_CONTEXT_OFFSET + i];
     }
 
     // may need to change if this class is redesigned

Modified: trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -155,7 +155,7 @@
                         log.warn("Class " + impl.getName() + " does not implement " + clazz.getName() + ". Ignoring."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                     }
                 }
-                catch (Exception ex)
+                catch (ClassNotFoundException ex)
                 {
                     log.warn("Failed to add class to list: " + clazz.getName(), ex); //$NON-NLS-1$
                 }
@@ -164,7 +164,7 @@
             log.debug("Found " + matches.size() + " implementors of " + clazz.getName()); //$NON-NLS-1$ //$NON-NLS-2$
             return (Class[]) matches.toArray(new Class[matches.size()]);
         }
-        catch (Exception ex)
+        catch (IOException ex)
         {
             log.error("Failed to get any classes.", ex); //$NON-NLS-1$
             return new Class[0];
@@ -206,7 +206,7 @@
                         log.warn("Class " + impl.getName() + " does not implement " + clazz.getName() + ". Ignoring."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                     }
                 }
-                catch (Exception ex)
+                catch (ClassNotFoundException ex)
                 {
                     log.warn("Failed to add class to list: " + clazz.getName(), ex); //$NON-NLS-1$
                 }
@@ -214,7 +214,7 @@
 
             log.debug("Found " + matches.size() + " implementors of " + clazz.getName()); //$NON-NLS-1$ //$NON-NLS-2$
         }
-        catch (Exception ex)
+        catch (IOException ex)
         {
             log.error("Failed to get any classes.", ex); //$NON-NLS-1$
         }

Modified: trunk/common/src/main/java/org/crosswire/common/util/Convert.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Convert.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/Convert.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -183,7 +183,7 @@
                     commands.put(key, value);
                 }
             }
-            catch (Exception ex)
+            catch (ClassNotFoundException ex)
             {
                 log.warn("Invalid config file entry: " + entry + " System message: " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
                 Reporter.informUser(Convert.class, ex);

Modified: trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -33,6 +33,8 @@
  * This code is lifted from javax.sw*ng.event.EventListnerList. It is
  * very useful in non GUI code which does not need the rest of sw*ng.
  * BORROWED: From javax.sw*ng.event.EventListnerList
+ * 
+ * <p>It differs in that it is fully synchronized, thus thread safe.
  *
  * <p>If you inculde sw*ng code in non-gui code then you can end up not being
  * able to run your code in a headerless environment because X includes Y which
@@ -54,8 +56,7 @@
  *
  * The main benefits which this class provides are that it is relatively
  * cheap in the case of no listeners, and provides serialization for
- * eventlistener lists in a single place, as well as a degree of MT safety
- * (when used correctly).
+ * eventlistener lists in a single place, as well as MT safety.
  *
  * Usage example:
  *    Say one is defining a class which sends out FooEvents, and wantds
@@ -115,25 +116,19 @@
 {
     /**
      * This passes back the event listener list as an array
-     * of ListenerType - listener pairs.  Note that for
-     * performance reasons, this implementation passes back
-     * the actual data structure in which the listner data
-     * is stored internally!
+     * of ListenerType - listener pairs.
+     * 
      * This method is guaranteed to pass back a non-null
      * array, so that no null-checking is required in
      * fire methods.  A zero-length array of Object should
      * be returned if there are currently no listeners.
-     *
-     * WARNING!!! Absolutely NO modification of
-     * the data contained in this array should be made -- if
-     * any such manipulation is necessary, it should be done
-     * on a copy of the array returned rather than the array
-     * itself.
      */
-    public Object[] getListenerList()
+    public synchronized Object[] getListenerList()
     {
-        Object[] lList = listenerList;
-        return lList;
+        int i = listenerList.length;
+        Object[] tmp = new Object[i];
+        System.arraycopy(listenerList, 0, tmp, 0, i);
+        return tmp;
     }
 
     /**
@@ -146,7 +141,7 @@
      */
     public EventListener[] getListeners(Class t)
     {
-        Object[] lList = listenerList;
+        Object[] lList = getListenerList();
         int n = getListenerCount(lList, t);
         EventListener[] result = (EventListener[]) Array.newInstance(t, n);
         int j = 0;
@@ -163,7 +158,7 @@
     /**
      * Returns the total number of listeners for this listener list.
      */
-    public int getListenerCount()
+    public synchronized int getListenerCount()
     {
         return listenerList.length / 2;
     }
@@ -174,7 +169,7 @@
      */
     public int getListenerCount(Class t)
     {
-        Object[] lList = listenerList;
+        Object[] lList = getListenerList();
         return getListenerCount(lList, t);
     }
 
@@ -288,7 +283,7 @@
      */
     private void writeObject(ObjectOutputStream oos) throws IOException
     {
-        Object[] lList = listenerList;
+        Object[] lList = getListenerList();
         oos.defaultWriteObject();
 
         // Save the non-null event listeners:

Modified: trunk/common/src/main/java/org/crosswire/common/util/LucidRuntimeException.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/LucidRuntimeException.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/LucidRuntimeException.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -48,7 +48,7 @@
      */
     public LucidRuntimeException(MsgBase msg)
     {
-        this(msg, null, (Object[]) null);
+        this(msg, null, null);
     }
 
     /**
@@ -58,7 +58,7 @@
      */
     public LucidRuntimeException(MsgBase msg, Throwable cause)
     {
-        this(msg, cause, (Object[]) null);
+        this(msg, cause, null);
     }
 
     /**
@@ -78,11 +78,11 @@
      * @param msg The resource id to read
      * @param params An array of parameters
      */
-    public LucidRuntimeException(MsgBase msg, Throwable cause, Object[] params)
+    public LucidRuntimeException(MsgBase msg, Throwable cause, Object[] newParams)
     {
         super(msg.toString(), cause);
 
-        this.params = (Object[]) params.clone();
+        this.params = newParams == null ? null : (Object[]) newParams.clone();
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/util/PatternFormatter.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/PatternFormatter.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/PatternFormatter.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -65,18 +65,11 @@
         String throwable = ""; //$NON-NLS-1$
         if (record.getThrown() != null)
         {
-            try
-            {
-                StringWriter sw = new StringWriter();
-                PrintWriter pw = new PrintWriter(sw);
-                record.getThrown().printStackTrace(pw);
-                pw.close();
-                throwable = sw.toString();
-            }
-            catch (Exception ex)
-            {
-                assert false;
-            }
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            record.getThrown().printStackTrace(pw);
+            pw.close();
+            throwable = sw.toString();
         }
 
         String format = LogManager.getLogManager().getProperty(PatternFormatter.class.getName() + ".format"); //$NON-NLS-1$

Modified: trunk/common/src/main/java/org/crosswire/common/util/Reporter.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Reporter.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/Reporter.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -228,22 +228,13 @@
             if (liArr[i] == ReporterListener.class)
             {
                 ReporterListener li = (ReporterListener) liArr[i + 1];
-                try
+                if (ev.getException() != null)
                 {
-                    if (ev.getException() != null)
-                    {
-                        li.reportException(ev);
-                    }
-                    else
-                    {
-                        li.reportMessage(ev);
-                    }
+                    li.reportException(ev);
                 }
-                catch (Exception ex)
+                else
                 {
-                    LISTENERS.remove(ReporterListener.class, li);
-
-                    log.warn("Dispatch failure", ex); //$NON-NLS-1$
+                    li.reportMessage(ev);
                 }
             }
         }

Modified: trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -54,7 +54,7 @@
      */
     public static URL getResource(String search) throws MissingResourceException
     {
-        return getResource(CallContext.instance().getCallingClass(), search);
+        return getResource(CallContext.getCallingClass(), search);
     }
 
     /**
@@ -84,7 +84,7 @@
      */
     public static InputStream getResourceAsStream(String search) throws IOException, MissingResourceException
     {
-        return getResourceAsStream(CallContext.instance().getCallingClass(), search);
+        return getResourceAsStream(CallContext.getCallingClass(), search);
     }
 
     /**
@@ -109,7 +109,7 @@
      */
     public static Properties getProperties(String subject) throws IOException, MissingResourceException
     {
-        return getProperties(CallContext.instance().getCallingClass(), subject);
+        return getProperties(CallContext.getCallingClass(), subject);
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/util/StackTrace.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/StackTrace.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/StackTrace.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -24,6 +24,7 @@
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 /**
  * Unscramble the current stack, and present the data from it to the
@@ -99,7 +100,7 @@
                     lineNumbers[i] = 0;
                 }
             }
-            catch (Exception ex2)
+            catch (NumberFormatException ex2)
             {
                 classNames[i] = "ParseError: "; //$NON-NLS-1$
                 methodNames[i] = call;
@@ -207,7 +208,7 @@
         /**
          * @return Returns the level.
          */
-        public int getAndIncrementLevel()
+        public int getAndIncrementLevel() throws NoSuchElementException
         {
             return level++;
         }
@@ -225,8 +226,12 @@
     {
         return new AbstractStackIterator()
         {
-            public Object next()
+            public Object next() throws NoSuchElementException
             {
+                if (!hasNext())
+                {
+                    throw new NoSuchElementException();
+                }
                 return getClassName(getAndIncrementLevel());
             }
         };
@@ -239,8 +244,12 @@
     {
         return new AbstractStackIterator()
         {
-            public Object next()
+            public Object next() throws NoSuchElementException
             {
+                if (!hasNext())
+                {
+                    throw new NoSuchElementException();
+                }
                 return getFunctionName(getAndIncrementLevel());
             }
         };
@@ -253,8 +262,12 @@
     {
         return new AbstractStackIterator()
         {
-            public Object next()
+            public Object next() throws NoSuchElementException
             {
+                if (!hasNext())
+                {
+                    throw new NoSuchElementException();
+                }
                 return getFullFunctionName(getAndIncrementLevel());
             }
         };

Deleted: trunk/common/src/main/java/org/crosswire/common/util/ThreadUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ThreadUtil.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/ThreadUtil.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -1,192 +0,0 @@
-/**
- * Distribution License:
- * JSword is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License, version 2.1 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/lgpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.common.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Various utilities for examining the running Threads and
- * controlling their execution.
- *
- * @see gnu.lgpl.License for license details.<br>
- *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public final class ThreadUtil
-{
-    /**
-     * Prevent Instansiation
-     */
-    private ThreadUtil()
-    {
-    }
-
-    /**
-     * Sleep and don't think about throwing. Mostly when a thread calls
-     * sleep you need to wrap it in a special try-catch block to get
-     * hold of the InterruptedException - which is rarely called and
-     * mostly ignored. This code takes care of the ignoring, and simply
-     * logs some stuff if InterruptedException do happen.
-     * @param millis The length of time to wait in milliseconds
-     * @see java.lang.InterruptedException
-     */
-    public static synchronized void soundSleep(long millis)
-    {
-        try
-        {
-            Thread.sleep(millis);
-        }
-        catch (InterruptedException ex)
-        {
-            Reporter.informUser(ThreadUtil.class, ex);
-        }
-    }
-
-    /**
-     * Find the root ThreadGroup by ascending the Thread tree
-     * @return The root ThreadGroup
-     */
-    public static ThreadGroup findRoot()
-    {
-        // Determine the current thread group
-        ThreadGroup top = Thread.currentThread().getThreadGroup();
-
-        // Proceed to the top ThreadGroup
-        while (top.getParent() != null)
-        {
-            top = top.getParent();
-        }
-
-        return top;
-    }
-
-    /**
-     * Create a StringArray (mostly for debugging) detailing the
-     * current Threads, starting at the root ThreadGroup
-     * @return The listing for all sub threads
-     */
-    public static String[] getListing()
-    {
-        return getListing(findRoot());
-    }
-
-    /**
-     * Create a StringArray (mostly for debugging) detailing the
-     * current Threads, starting at the specified ThreadGroup
-     * @param base The ThreadGroup to detail
-     * @return The listing for all sub threads
-     */
-    public static String[] getListing(ThreadGroup base)
-    {
-        List list = new ArrayList();
-
-        listThreads(list, 0, base);
-
-        return (String[]) list.toArray(new String[list.size()]);
-    }
-
-    /**
-     * Private, used by getListing. Adds to a List the sub-threads
-     * @param list The List to add to.
-     * @param depth The current recursion depth
-     * @param group The ThreadGroup to detail
-     */
-    private static void listThreads(List list, int depth, ThreadGroup group)
-    {
-        if (group == null)
-        {
-            return;
-        }
-
-        try
-        {
-            int num_threads = group.activeCount();
-            int num_groups = group.activeGroupCount();
-
-            Thread[] threads = new Thread[num_threads];
-            ThreadGroup[] groups = new ThreadGroup[num_groups];
-
-            group.enumerate(threads, false);
-            group.enumerate(groups, false);
-
-            try
-            {
-                addItem(list, depth, group.getName());
-            }
-            catch (SecurityException ex)
-            {
-                addItem(list, depth, Msg.UNAVILABLE.toString());
-            }
-
-            for (int i = 0; i < num_threads; i++)
-            {
-                listThread(list, depth + 1, threads[i]);
-            }
-
-            for (int i = 0; i < num_groups; i++)
-            {
-                listThreads(list, depth + 1, groups[i]);
-            }
-        }
-        catch (Exception ex)
-        {
-            addItem(list, depth, ex.toString());
-        }
-    }
-
-    /**
-     * Private, used by getListing. Adds to a List the sub-threads
-     * @param list The List to add to.
-     * @param depth The current recursion depth
-     * @param thread The Thread to detail
-     */
-    private static void listThread(List list, int depth, Thread thread)
-    {
-        if (thread == null)
-        {
-            return;
-        }
-
-        try
-        {
-            addItem(list, depth, thread.getName() + " (" + thread.getPriority() + ')'); //$NON-NLS-1$
-        }
-        catch (SecurityException ex)
-        {
-            addItem(list, depth, Msg.UNAVILABLE.toString());
-        }
-    }
-
-    /**
-     * Private, used by getListing. Adds to a List the sub-threads
-     * @param list The List to add to.
-     * @param depth The current recursion depth
-     */
-    private static void addItem(List list, int depth, String item)
-    {
-        list.add(PADDING.substring(0, depth * 2) + item);
-    }
-
-    private static final String PADDING = "                                                                "; //$NON-NLS-1$
-
-}

Modified: trunk/common/src/main/java/org/crosswire/common/util/WebResource.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/WebResource.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/util/WebResource.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -21,6 +21,7 @@
  */
 package org.crosswire.common.util;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
@@ -89,9 +90,9 @@
                 return connection.getContentLength();
             }
             String reason = HttpStatus.getStatusText(status);
-            Reporter.informUser(this, reason + ": " + url.getFile()); //$NON-NLS-1$
+            Reporter.informUser(this, Msg.MISSING_FILE, new Object[] { reason + ':' + url.getFile() });
         }
-        catch (Exception e)
+        catch (IOException e)
         {
             return 0;
         }
@@ -122,7 +123,7 @@
                 return connection.getLastModified();
             }
         }
-        catch (Exception e)
+        catch (IOException e)
         {
             return new Date().getTime();
         }
@@ -166,7 +167,7 @@
                 }
             }
         }
-        catch (Exception e)
+        catch (IOException e)
         {
             throw new LucidException(Msg.MISSING_FILE, e);
         }

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLFeature.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLFeature.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLFeature.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -114,7 +114,7 @@
         for (int i = 0; i < VALUES.length; i++)
         {
             XMLFeature o = VALUES[i];
-            if (o.name.equalsIgnoreCase(name))
+            if (o.control.equalsIgnoreCase(name))
             {
                 return o;
             }
@@ -169,10 +169,6 @@
 
     private String control;
     private boolean state;
-    /**
-     * The name of the PassageListType
-     */
-    private String name;
 
     // Support for serialization
     private static int nextObj;

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -163,7 +163,7 @@
     /**
      * A holder of the boolean state for a feature.
      */
-    private class XMLFeatureState
+    private static class XMLFeatureState
     {
         public XMLFeatureState(XMLFeature feature, boolean state)
         {

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -21,6 +21,8 @@
  */
 package org.crosswire.common.xml;
 
+import java.io.IOException;
+
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 import org.xml.sax.XMLReader;
@@ -151,7 +153,7 @@
         {
             parser = XMLReaderFactory.createXMLReader(parserName);
         }
-        catch (Exception e)
+        catch (SAXException e)
         {
             System.err.println("error: Unable to instantiate parser (" + parserName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
         }
@@ -169,10 +171,18 @@
         {
             adapter = (XMLHandlerAdapter) Class.forName(adapterName).newInstance();
         }
-        catch (Exception e)
+        catch (ClassNotFoundException e)
         {
             System.err.println("error: Unable to instantiate XMLHandlerAdpater (" + adapterName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
         }
+        catch (InstantiationException e)
+        {
+            System.err.println("error: Unable to instantiate XMLHandlerAdpater (" + adapterName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        catch (IllegalAccessException e)
+        {
+            System.err.println("error: Unable to instantiate XMLHandlerAdpater (" + adapterName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
 
     }
 
@@ -213,17 +223,21 @@
         {
             // ignore
         }
-        catch (Exception e)
+        catch (SAXException e)
         {
             System.err.println("error: Parse error occurred - " + e.getMessage()); //$NON-NLS-1$
-            if (e instanceof SAXException)
+            Exception nested = e.getException();
+            if (nested != null)
             {
-                Exception nested = ((SAXException) e).getException();
-                if (nested != null)
-                {
-                    e = nested;
-                }
+                nested.printStackTrace(System.err);
             }
+            else
+            {
+                e.printStackTrace(System.err);
+            }
+        }
+        catch (IOException e)
+        {
             e.printStackTrace(System.err);
         }
     }

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -373,7 +373,7 @@
     /**
      * The log stream
      */
-    protected static final Logger log = Logger.getLogger(XMLUtil.class);
+    private static final Logger log = Logger.getLogger(XMLUtil.class);
 
     private static Pattern validCharacterEntityPattern = Pattern.compile("^&#x?\\d{2,4};"); //$NON-NLS-1$
 }

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -21,6 +21,7 @@
  */
 package org.crosswire.common.xml;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
@@ -63,11 +64,18 @@
                 clazz = Class.forName("com.sun.org.apache.xalan.internal.xslt.Process"); //$NON-NLS-1$
                 main = clazz.getMethod("_main", new Class[] {String[].class}); //$NON-NLS-1$
             }
-            catch (Exception e1)
+            catch (ClassNotFoundException e1)
             {
                 e1.printStackTrace();
-                return;
             }
+            catch (SecurityException e1)
+            {
+                e1.printStackTrace();
+            }
+            catch (NoSuchMethodException e1)
+            {
+                e1.printStackTrace();
+            }
         }
         catch (NoSuchMethodException e)
         {
@@ -77,11 +85,22 @@
 
         try
         {
-            main.invoke(null, new Object[] { args });
+            if (main != null)
+            {
+                main.invoke(null, new Object[] { args });
+            }
         }
-        catch (Exception e)
+        catch (IllegalArgumentException e)
         {
+             e.printStackTrace();
+        }
+        catch (IllegalAccessException e)
+        {
             e.printStackTrace();
         }
+        catch (InvocationTargetException e)
+        {
+            e.printStackTrace();
+        }
     }
 }

Modified: trunk/common/src/test/java/org/crosswire/common/util/AllTests.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/util/AllTests.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/test/java/org/crosswire/common/util/AllTests.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -39,7 +39,6 @@
         //$JUnit-BEGIN$
         suite.addTest(new TestSuite(HelpDeskTest.class));
         suite.addTest(new TestSuite(StringUtilTest.class));
-        suite.addTest(new TestSuite(ThreadUtilTest.class));
         //$JUnit-END$
         return suite;
     }

Deleted: trunk/common/src/test/java/org/crosswire/common/util/ThreadUtilTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/util/ThreadUtilTest.java	2006-10-10 14:28:18 UTC (rev 1149)
+++ trunk/common/src/test/java/org/crosswire/common/util/ThreadUtilTest.java	2006-10-10 23:28:31 UTC (rev 1150)
@@ -1,64 +0,0 @@
-/**
- * Distribution License:
- * JSword is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License, version 2.1 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/lgpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.common.util;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit Test.
- * 
- * @see gnu.lgpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public class ThreadUtilTest extends TestCase
-{
-    public ThreadUtilTest(String s)
-    {
-        super(s);
-    }
-
-    String NEWLINE = System.getProperty("line.separator", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
-
-    /* @Override */
-    protected void setUp() throws Exception
-    {
-    }
-
-    /* @Override */
-    protected void tearDown() throws Exception
-    {
-    }
-
-    public void testFindRoot() throws Exception
-    {
-        assertTrue(ThreadUtil.findRoot() != null);
-    }
-
-    public void testGetListing() throws Exception
-    {
-        /*
-        String[] result = ThreadUtil.getListing();
-        String result2 = StringUtil.cat(result, NEWLINE);
-        */
-    }
-}




More information about the jsword-svn mailing list