Anonymous avatar Anonymous committed a56ae4c

Issue number: WW-1243, WW-1244
Obtained from:
Submitted by:
Reviewed by:

Since there was a warning message issued in typical doubleselect usage, w/o affecting correct functionality, came up to this:
Lower verbosity for caught exceptions during expression evaluation, based on devMode flag
- if devMode is true, keep level WARN and inform that this level relates to the devMode flag
- if devMode is false/not set, lower log level to DEDUG to keep user from being scared up for no reason

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@909 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

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

     }
 
     /**
+     * Determine whether devMode is enabled.
+     * @return true if devMode was enabled, false otherwise.
+     */
+    public boolean isDevModeEnabled() {
+        Boolean devMode = (Boolean) context.get(ActionContext.DEV_MODE);
+        if (devMode != null) {
+        	return devMode.booleanValue();
+        } else {
+            return false;
+        }
+    }
+
+    /**
      * Attempts to set a property on a bean in the stack with the given expression using the default search order.
      *
      * @param expr  the expression defining the path to the property to be set.
      * @param value the value to be set into the neamed property
      */
     public void setValue(String expr, Object value) {
-        boolean report = false;
-        Boolean devMode = (Boolean) context.get(ActionContext.DEV_MODE);
-        if (devMode != null) {
-            report = devMode.booleanValue();
-        }
-
-        setValue(expr, value, report);
+        setValue(expr, value, isDevModeEnabled());
     }
 
     /**
         } catch (OgnlException e) {
             return findInContext(expr);
         } catch (Exception e) {
-            LOG.warn("Caught an exception while evaluating expression '" + expr + "' against value stack", e);
+            StringBuffer msg = new StringBuffer();
+            msg.append("Caught an exception while evaluating expression '").append(expr).append("' against value stack");
+            if (isDevModeEnabled() && LOG.isWarnEnabled()) {
+                LOG.warn( msg , e);
+                LOG.warn("NOTE: Previous warning message was issued due to devMode set to true.");
+            } else if ( LOG.isDebugEnabled() ) {
+                LOG.debug( msg , e);
+            }
 
             return findInContext(expr);
         } finally {

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

         assertTrue(conversionErrors.containsKey("count"));
     }
 
+    public void testIsDevModeEnabled() {
+        OgnlValueStack stack = new OgnlValueStack();
+        assertFalse(stack.isDevModeEnabled());
+        stack.getContext().put(ActionContext.DEV_MODE, Boolean.FALSE);
+        assertFalse(stack.isDevModeEnabled());
+        stack.getContext().put(ActionContext.DEV_MODE, Boolean.TRUE);
+        assertTrue(stack.isDevModeEnabled());
+    }
 
     class BadJavaBean {
         private int count;
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.