Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed NPE if model is empty but globals are defined.

  • Loading branch information...
commit 7b6b35435c10b5d4e0ad3022ad2df3b5f752e57a 1 parent db42114
Chris Dance authored
2  pom.xml
@@ -4,7 +4,7 @@
4 4 <groupId>com.papercut.silken</groupId>
5 5 <artifactId>silken</artifactId>
6 6 <packaging>jar</packaging>
7   - <version>2012-02-23</version>
  7 + <version>2012-02-27-SNAPSHOT</version>
8 8 <name>silken</name>
9 9 <url>https://github.com/codedance/silken</url>
10 10 <description>Silken - a nicer tasting Soy Tofu (Google Closure Templates)</description>
7 src/main/java/com/papercut/silken/SilkenServlet.java
@@ -282,10 +282,12 @@ private void doRequest(HttpServletRequest req, HttpServletResponse resp) throws
282 282 SoyMapData model = config.getModelResolver().resolveModel(req);
283 283 SoyMapData globals = null;
284 284 if (config.getRuntimeGlobalsProvider() != null) {
285   -
286 285 // Merge globals into the model
287 286 globals = config.getRuntimeGlobalsProvider().getGlobals(req);
288   - model = Utils.mergeSoyMapData(model, globals);
  287 + if (model != null && globals != null) {
  288 + // If keys in global clash with model, model wins.
  289 + model = Utils.mergeSoyMapData(globals, model);
  290 + }
289 291 }
290 292
291 293 // FUTURE: A mime type resolver and character type encoding?
@@ -294,7 +296,6 @@ private void doRequest(HttpServletRequest req, HttpServletResponse resp) throws
294 296 resp.getWriter().print(templateRenderer.render(templateName, model, globals, locale));
295 297 return;
296 298
297   -
298 299 } catch (Exception e) {
299 300 error(req, resp, e);
300 301 }
5 src/main/java/com/papercut/silken/Utils.java
@@ -129,12 +129,15 @@ public static Object toSoyCompatibleObjects(Object obj) {
129 129 }
130 130
131 131 /**
132   - * Merge two SoyMapData resources.
  132 + * Merge two SoyMapData resources. If the two maps to merge contain duplicate key names, source
  133 + * s2 will overwrite s1.
133 134 * @param s1 1st resource map.
134 135 * @param s2 2nd resource map.
135 136 * @return A new SoyMapData object containing data from both source.
136 137 */
137 138 public static SoyMapData mergeSoyMapData(SoyMapData s1, SoyMapData s2) {
  139 + Preconditions.checkNotNull(s1);
  140 + Preconditions.checkNotNull(s2);
138 141 SoyMapData merged = new SoyMapData();
139 142 for (String key: s1.getKeys()) {
140 143 merged.putSingle(key, s1.getSingle(key));

0 comments on commit 7b6b354

Please sign in to comment.
Something went wrong with that request. Please try again.