lift / lift/framework

LiftRules.throwOnOutOfScopeVarAccess broken?

Open
#1,063 2 comments 0 reactions 1 assignee View on GitHub

@dpp is already working on this.

Since Mar 1, 2012.

P:Normal T:Defect
Dominant language
Scala
Stars
1.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

Copied from http://groups.google.com/group/liftweb/browse_thread/thread/54e059516001a518

For example, trying to use
a SessionVar before the session has been created shouldn't just refuse to be set. It
would be nice to have an exception reporting the problem.

I think your points are valid to a certain degree, but for this
specific problem there's a solution in LiftRules:

/**

  • Should an exception be thrown on out of scope Session and RequestVar
  • access. By default, no.
    */
    @volatile var throwOnOutOfScopeVarAccess: Boolean = false

/Jeppe

Thanks for the pointer, but I don't think it's working. After messing around with it in my own project, I did the following:

  1. downloaded the examples from https://github.com/lift/lift_23_sbt.git

  2. Compiled and ran fine using sbt

  3. Added

    // Find out if we access SessionVars or RequestVars inappropriately..
    LiftRules.throwOnOutOfScopeVarAccess = true

    as the last line in Boot.boot

  4. Ran again and it threw an exception:

[info] == jetty-run ==
[success] Successful.
[info]
[info] Total time: 2 s, completed Jun 30, 2011 11:48:02 AM

11:48:04.848 [1193485506@qtp-1743791445-0] ERROR net.liftweb.http.LiftRules$$anon$1 - Exception being returned to browser when processing /: Message: java.lang.IllegalAccessException: Access to SessionVar outside a request or comet actor scope
net.liftweb.http.SessionVar.findFunc(Vars.scala:71)
net.liftweb.util.AnyVarTrait$$anonfun$is$1.apply(AnyVar.scala:137)
net.liftweb.http.SessionVar.doSync(Vars.scala:125)
net.liftweb.util.AnyVarTrait$class.is(AnyVar.scala:136)
net.liftweb.util.AnyVar.is(AnyVar.scala:89)
net.liftweb.util.AnyVarTrait$class.get(AnyVar.scala:161)
net.liftweb.util.AnyVar.get(AnyVar.scala:89)
net.liftweb.util.StackableMaker$class.find(Maker.scala:150)
net.liftweb.http.Factory$FactoryMaker.find(Factory.scala:37)
net.liftweb.http.Factory$FactoryMaker$$anonfun$make$1.apply(Factory.scala:87)
net.liftweb.http.Factory$FactoryMaker$$anonfun$make$1.apply(Factory.scala:87)
net.liftweb.common.EmptyBox.or(Box.scala:563)
net.liftweb.http.Factory$FactoryMaker.make(Factory.scala:87)
net.liftweb.http.Factory$FactoryMaker.vend(Factory.scala:82)
net.liftweb.http.S$class.statelessInit(S.scala:1186)
net.liftweb.http.LiftServlet.doService(LiftServlet.scala:244)
net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:122)
net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:121)

(lots omitted)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.