Author: lukaszlenart
Date: Mon Jan 21 11:37:16 2013
New Revision: 1436290

URL: http://svn.apache.org/viewvc?rev=1436290&view=rev
Log:
Solves problem with possible NPE when key is null - 
https://github.com/apache/struts2/pull/4

Modified:
    
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java

Modified: 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java?rev=1436290&r1=1436289&r2=1436290&view=diff
==============================================================================
--- 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java
 (original)
+++ 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java
 Mon Jan 21 11:37:16 2013
@@ -408,18 +408,18 @@ public class JSONWriter {
             }
 
             Object key = entry.getKey();
+            if (key == null) {
+                LOG.error("Cannot build expression for null key in #0", 
exprStack);
+                continue;
+            }
+
             String expr = null;
             if (this.buildExpr) {
-                if (key == null) {
-                    LOG.error("Cannot build expression for null key in " + 
this.exprStack);
+                expr = this.expandExpr(key.toString());
+                if (this.shouldExcludeProperty(expr)) {
                     continue;
-                } else {
-                    expr = this.expandExpr(key.toString());
-                    if (this.shouldExcludeProperty(expr)) {
-                        continue;
-                    }
-                    expr = this.setExprStack(expr);
                 }
+                expr = this.setExprStack(expr);
             }
             if (hasData) {
                 this.add(',');
@@ -427,8 +427,7 @@ public class JSONWriter {
             hasData = true;
             if (!warnedNonString && !(key instanceof String)) {
                 if (LOG.isWarnEnabled()) {
-                    LOG.warn("JavaScript doesn't support non-String keys, 
using toString() on "
-                        + key.getClass().getName());
+                    LOG.warn("JavaScript doesn't support non-String keys, 
using toString() on #0", key.getClass().getName());
                 }
                 warnedNonString = true;
             }


Reply via email to