When running Scalatra tests, NPE is thrown due to url method in layout templates #368

Open
seratch opened this Issue Mar 3, 2014 · 4 comments

Comments

Projects
None yet
1 participant
@seratch
Owner

seratch commented Mar 3, 2014

When using url method (e.g. url(Controller.someScalatraRerverseRouteURL)) in src/main/webapp/WEB-INF/layouts/default.jade, NPE is thrown only when running Scalatra tests.

After removing url method from default.jade, everything goes fine. Basically we shouldn't use url method?

java.lang.NullPointerException: null
        at org.scalatra.servlet.ServletBase$$anon$1.context(ServletBase.scala:26) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.ScalatraBase$class.servletContext(ScalatraBase.scala:121) [scalatra_2.10-2.2.2.jar:2.2.2]
        at skinny.controller.SkinnyController.servletContext(SkinnyController.scala:6) [skinny-framework_2.10-1.0.0-RC6-SNAPSHOT.jar:1.0.0-RC6-SNAPSHOT]
        at org.scalatra.ScalatraFilter$class.routeBasePath(ScalatraFilter.scala:66) [scalatra_2.10-2.2.2.jar:2.2.2]
        at skinny.controller.SkinnyController.routeBasePath(SkinnyController.scala:6) [skinny-framework_2.10-1.0.0-RC6-SNAPSHOT.jar:1.0.0-RC6-SNAPSHOT]
        at org.scalatra.ScalatraBase$$anonfun$7.apply(ScalatraBase.scala:529) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.ScalatraBase$$anonfun$7.apply(ScalatraBase.scala:529) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.UrlGeneratorSupport$class.url(UrlGenerator.scala:55) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.UrlGenerator$.url(UrlGenerator.scala:61) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.UrlGeneratorSupport$class.url(UrlGenerator.scala:21) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.UrlGenerator$.url(UrlGenerator.scala:61) ~[scalatra_2.10-2.2.2.jar:2.2.2]
        at org.scalatra.scalate.ScalatraRenderContext.url(ScalatraRenderContext.scala:86) ~[scalatra-scalate_2.10-2.2.2.jar:2.2.2]
        at templates.layouts.$_scalate_$default_jade$.$_scalate_$render(default.jade.scala:86) ~[na:na]
        at templates.layouts.$_scalate_$default_jade.render(default.jade.scala:138) ~[na:na]
        at org.fusesource.scalate.layout.DefaultLayoutStrategy.org$fusesource$scalate$layout$DefaultLayoutStrategy$$tryLayout(DefaultLayoutStrategy.scala:77) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.layout.DefaultLayoutStrategy$$anonfun$1.apply(DefaultLayoutStrategy.scala:59) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.layout.DefaultLayoutStrategy$$anonfun$1.apply(DefaultLayoutStrategy.scala:59) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at scala.collection.LinearSeqOptimized$class.find(LinearSeqOptimized.scala:100) ~[scala-library.jar:0.13.1]
        at scala.collection.immutable.List.find(List.scala:84) ~[scala-library.jar:0.13.1]
        at org.fusesource.scalate.layout.DefaultLayoutStrategy.layout(DefaultLayoutStrategy.scala:59) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(TemplateEngine.scala:559) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.RenderContext$class.withUri(RenderContext.scala:447) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.DefaultRenderContext.withUri(DefaultRenderContext.scala:30) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1.apply$mcV$sp(TemplateEngine.scala:558) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1.apply(TemplateEngine.scala:555) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1.apply(TemplateEngine.scala:555) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.RenderContext$.using(RenderContext.scala:47) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:555) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:547) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:601) ~[scalate-core_2.10-1.6.1.jar:1.6.1]
        at org.scalatra.scalate.ScalateSupport$class.layoutTemplateAs(ScalateSupport.scala:223) [scalatra-scalate_2.10-2.2.2.jar:2.2.2]
        at skinny.controller.SkinnyController.layoutTemplateAs(SkinnyController.scala:6) [skinny-framework_2.10-1.0.0-RC6-SNAPSHOT.jar:1.0.0-RC6-SNAPSHOT]
        at org.scalatra.scalate.ScalateSupport$class.layoutTemplate(ScalateSupport.scala:236) [scalatra-scalate_2.10-2.2.2.jar:2.2.2]
        at skinny.controller.SkinnyController.layoutTemplate(SkinnyController.scala:6) [skinny-framework_2.10-1.0.0-RC6-SNAPSHOT.jar:1.0.0-RC6-SNAPSHOT]
@seratch

This comment has been minimized.

Show comment Hide comment
@seratch

seratch Mar 13, 2014

Owner

When reversed routes have some parameters, we need to use url method. This issue should be fixed.

<a href="${url(SomeController.reversedRoute, "id" -> "123")}">something</a>
Owner

seratch commented Mar 13, 2014

When reversed routes have some parameters, we need to use url method. This issue should be fixed.

<a href="${url(SomeController.reversedRoute, "id" -> "123")}">something</a>
@seratch

This comment has been minimized.

Show comment Hide comment
@seratch

seratch Mar 13, 2014

Owner

Just tried 2.3.0-SNAPSHOT and the issue seems to be fixed. I can hardly wait for 2.3.0 stable release!

Owner

seratch commented Mar 13, 2014

Just tried 2.3.0-SNAPSHOT and the issue seems to be fixed. I can hardly wait for 2.3.0 stable release!

@seratch seratch closed this Mar 13, 2014

@seratch

This comment has been minimized.

Show comment Hide comment
@seratch

seratch Mar 14, 2014

Owner

Sorry, my check with 2.3.0-SNAPSHOT was invalid. I'm not sure this issue is fixed.

Owner

seratch commented Mar 14, 2014

Sorry, my check with 2.3.0-SNAPSHOT was invalid. I'm not sure this issue is fixed.

@seratch seratch reopened this Mar 14, 2014

seratch added a commit to skinny-framework/skinny-framework that referenced this issue Apr 30, 2014

seratch added a commit to skinny-framework/skinny-framework that referenced this issue Apr 30, 2014

version 1.0.10
 - [blank-app] Set skinny.env as test to JVM options when testing
 - [framework] Work around for scalatra/scalatra#368
 - [http-client] Implemented skinny-http-client based on m3dev/curly library
 - [http-client] Fixed http-client logging, default ua
 - [http-client] Refactored thanks to @martin-g's feedback
 - [orm] #120 Flattens Options when using StrongParameter by @lloydmeta

seratch added a commit to skinny-framework/skinny-framework that referenced this issue Apr 30, 2014

version 1.0.11
- [blank-app] Set skinny.env as test to JVM options when testing
- [framework] Work around for scalatra/scalatra#368
- [http-client] Implemented skinny-http-client based on m3dev/curly library
- [http-client] Fixed http-client logging, default ua
- [http-client] Refactored thanks to @martin-g's feedback
- [orm] #120 Flattens Options when using StrongParameter by @lloydmeta
- [orm] ScalikeJDBC 1.7.6 to fix ReadOnlyAutoSession issue
- [factory-girl] twitter/util-eval 6.14.0

seratch added a commit to skinny-framework/skinny-framework that referenced this issue Jul 30, 2014

version 1.2.6
 - [framework] Fix JSONStringOps#fromJSONString ignores asIs flag
 - [test] Improved MockController features (merged from @namutaka's code)
 - [test] Fix using #url in controllers causes NPE when testing (scalatra/scalatra#368)

@seratch seratch added the bug label Dec 9, 2014

@seratch seratch self-assigned this Dec 9, 2014

@seratch

This comment has been minimized.

Show comment Hide comment
@seratch

seratch Jan 11, 2015

Owner

I tried to write a test suite which simply reproduces this error in Scalatra project, but somehow I couldn't reproduce the situation in Scalatra project. I should investigate more.

Owner

seratch commented Jan 11, 2015

I tried to write a test suite which simply reproduces this error in Scalatra project, but somehow I couldn't reproduce the situation in Scalatra project. I should investigate more.

@seratch seratch added the test label Feb 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment