Commits

Anonymous committed 57a8892

RuntimeException should be replaced with proper exception handling
o replaced all occurances of RuntimeException with XworkException
Issue Number: XW-102

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2/src@1071e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (13)

java/com/opensymphony/xwork/ObjectFactory.java

                     try {
                         byte[] bytes = ClassByteUtil.getBytes(name, parent);
                         if (bytes == null) {
-                            throw new RuntimeException("Continuation error: no bytes loaded");
+                            throw new XworkException("Continuation error: no bytes loaded");
                         }
 
                         byte[] resume_bytes = null;
                             return defineClass(name, resume_bytes, 0, resume_bytes.length);
                         }
                     } catch (IOException e) {
-                        throw new RuntimeException("Continuation error", e);
+                        throw new XworkException("Continuation error", e);
                     }
                 } else {
                     return clazz;

java/com/opensymphony/xwork/interceptor/ParametersInterceptor.java

 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ValidationAware;
+import com.opensymphony.xwork.XworkException;
 import com.opensymphony.xwork.util.*;
 
 import java.util.Iterator;
                 Object value = entry.getValue();
                 try {
                     stack.setValue(name, value);
-                } catch (RuntimeException e) {
+                } catch (XworkException e) {
                     final Boolean devMode = (Boolean) stack.getContext().get(ActionContext.DEV_MODE);
                     if (devMode != null && devMode.booleanValue()) {
                         String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "webwork.messages.devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification (set webwork.devMode to false to disable this message):\n{0}", new Object[]{

java/com/opensymphony/xwork/interceptor/component/ComponentConfiguration.java

 package com.opensymphony.xwork.interceptor.component;
 
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.XworkException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
             return ObjectFactory.getObjectFactory().getClassInstance(enablerClass);
         } catch (ClassNotFoundException e) {
             log.fatal("Cannot load class : " + enablerClass, e);
-            throw new RuntimeException("Cannot load class : " + enablerClass);
+            throw new XworkException("Cannot load class : " + enablerClass);
         }
     }
 

java/com/opensymphony/xwork/interceptor/component/DefaultComponentManager.java

 
 import com.opensymphony.util.ClassLoaderUtil;
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.XworkException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
         } catch (Exception e) {
             String message = "Could not load resource with enabler " + enablerType;
             log.error(message, e);
-            throw new RuntimeException(message);
+            throw new XworkException(message);
         }
     }
 
             this.fallback = (DefaultComponentManager) fallback;
             this.config = fallback.getConfig();
         } else {
-            throw new RuntimeException("Fallback must be an instance of DefaultConfigurationManager");
+            throw new XworkException("Fallback must be an instance of DefaultConfigurationManager");
         }
     }
 
         } catch (Exception e) {
             String message = "Could not load resource of type " + componentType;
             log.error(message, e);
-            throw new RuntimeException(message);
+            throw new XworkException(message);
         }
     }
 

java/com/opensymphony/xwork/util/CompoundRootAccessor.java

 import java.beans.PropertyDescriptor;
 import java.util.*;
 
+import com.opensymphony.xwork.XworkException;
+
 
 /**
  * A stack that is able to call methods on objects in the stack.
 //                if (e.getReason() != null) {
 //                    final String msg = "Caught an Ognl exception while setting property " + name;
 //                    log.error(msg, e);
-//                    throw new RuntimeException(msg, e.getReason());
+//                    throw new XworkException(msg, e.getReason());
 //                }
             } catch (IntrospectionException e) {
                 // this is OK if this happens, we'll just keep trying the next
 
         if ((reportError != null) && (reportError.booleanValue())) {
             log.error(msg);
-            throw new RuntimeException(msg);
+            throw new XworkException(msg);
         } else {
             log.debug(msg);
         }
                     if (e.getReason() != null) {
                         final String msg = "Caught an Ognl exception while getting property " + name;
                         log.error(msg, e);
-                        throw new RuntimeException(msg, e);
+                        throw new XworkException(msg, e);
                     }
                 } catch (IntrospectionException e) {
                     // this is OK if this happens, we'll just keep trying the next
                     String s = (String) iterator.next();
                     sb.append(s).append("\n");
                 }
-                
+
                 return sb.toString();
             } catch (IntrospectionException e) {
                 e.printStackTrace();

java/com/opensymphony/xwork/util/OgnlUtil.java

 import java.util.Iterator;
 import java.util.Map;
 
+import com.opensymphony.xwork.XworkException;
+
 
 /**
  * Utility class that provides common access to the Ognl APIs for
 
             if (throwPropertyExceptions) {
                 log.error(msg, exception);
-                throw new RuntimeException(msg, exception);
+                throw new XworkException(msg, exception);
             } else {
                 log.warn(msg, exception);
             }

java/com/opensymphony/xwork/util/OgnlValueStack.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.DefaultTextProvider;
+import com.opensymphony.xwork.XworkException;
 import ognl.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
             if (throwExceptionOnFailure) {
                 String msg = "Error setting expr '" + expr + "' with value '" + value + "'";
                 LOG.error(msg, e);
-                throw new RuntimeException(msg, e);
+                throw new XworkException(msg, e);
             } else {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Error setting value", e);
                 }
             }
-        } catch (RuntimeException re) { //XW-281
+        } catch (XworkException re) { //XW-281
             if (throwExceptionOnFailure) {
                 String msg = "Error setting expr '" + expr + "' with value '" + value + "'";
                 LOG.error(msg, re);
                     LOG.debug("Error setting value", re);
                 }
             }
+        } catch (RuntimeException re) { //XW-281
+            if (throwExceptionOnFailure) {
+                String msg = "Error setting expr '" + expr + "' with value '" + value + "'";
+                LOG.error(msg, re);
+                throw new XworkException(msg, re);
+            } else {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Error setting value", re);
+                }
+            }
         } finally {
             OgnlContextState.clear(context);
             context.remove(XWorkConverter.CONVERSION_PROPERTY_FULLNAME);

java/com/opensymphony/xwork/util/XWorkList.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.XworkException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
                 //todo
                 this.add(ObjectFactory.getObjectFactory().buildBean(clazz, null)); //ActionContext.getContext().getContextMap()));
             } catch (Exception e) {
-                throw new RuntimeException(e.getMessage());
+                throw new XworkException(e.getMessage());
             }
         }
 

java/com/opensymphony/xwork/util/XWorkListPropertyAccessor.java

 package com.opensymphony.xwork.util;
 
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.XworkException;
 import ognl.ListPropertyAccessor;
 import ognl.OgnlException;
 
                 try {
                     list.add(index, result = ObjectFactory.getObjectFactory().buildBean(beanClass, context));
                 } catch (Exception exc) {
-                    throw new RuntimeException(exc);
+                    throw new XworkException(exc);
                 }
                 return result;
             } else if (list.get(index) == null) {
                 try {
                     list.set(index, result = ObjectFactory.getObjectFactory().buildBean(beanClass, context));
                 } catch (Exception exc) {
-                    throw new RuntimeException(exc);
+                    throw new XworkException(exc);
                 }
                 return result;
             }

java/com/opensymphony/xwork/util/XWorkMap.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.XworkException;
 
 import java.util.HashMap;
 import java.util.Iterator;
                 o = ObjectFactory.getObjectFactory().buildBean(clazz, null); // ActionContext.getContext().getContextMap());
                 this.put(key, o);
             } catch (Exception e) {
-                throw new RuntimeException(e.getMessage());
+                throw new XworkException(e.getMessage());
             }
         }
 

test/com/opensymphony/xwork/interceptor/LifecycleInterceptorTest.java

 			if (! bool.booleanValue()) {
 				return super.execute();
 			} else {
-				throw new RuntimeException("Forced Exception");
+				throw new XworkException("Forced Exception");
 			}
 		}
 		

test/com/opensymphony/xwork/util/OgnlUtilTest.java

 
                             return param;
                         } catch (Exception e) {
-                        	throw new RuntimeException(e);
+                        	throw new XworkException(e);
                         }
                     }
                 }
             stack.setValue("list.1114778947765", foo);
             fail("non-valid expression: list.1114778947765"); 
         }
-        catch(RuntimeException ex) {
+        catch(XworkException ex) {
             ; // it's oke
         }
         
             stack.setValue("1114778947765", foo);
             fail("non-valid expression: 1114778947765"); 
         }
-        catch(RuntimeException ex) {
+        catch(XworkException ex) {
             ;
         }
         
             stack.setValue("1234", foo);
             fail("non-valid expression: 1114778947765"); 
         }
-        catch(RuntimeException ex) {
+        catch(XworkException ex) {
             ;
         }
         

test/com/opensymphony/xwork/util/OgnlValueStackTest.java

         try {
             vs.setValue("count", "1", true);
             fail("Expected an exception for mismatched getter and setter");
-        } catch (RuntimeException e) {
+        } catch (XworkException e) {
             //expected
         }
 
         try {
             vs.setValue("count2", "a", true);
             fail("Expected an exception for mismatched getter and setter");
-        } catch (RuntimeException e) {
+        } catch (XworkException e) {
             //expected
         }
     }
 
         try {
             vs.setValue("count", "1");
-        } catch (RuntimeException e) {
+        } catch (XworkException e) {
             fail("Unexpected exception for mismatched getter and setter");
         }
 
         try {
             vs.setValue("count2", "a");
-        } catch (RuntimeException e) {
+        } catch (XworkException e) {
             fail("Unexpected exception for mismatched getter and setter");
         }
     }
         
         try {
             stack.setValue("bar", "3x");
-            fail("Attempt to set 'bar' int property to '3x' should result in RuntimeException");
+            fail("Attempt to set 'bar' int property to '3x' should result in XworkException");
         }
-        catch(RuntimeException re) {
+        catch(XworkException re) {
             assertTrue(true);
         }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.