fwbrasil / activate

Abandoned: Pluggable persistence in Scala
GNU Lesser General Public License v2.1
299 stars 46 forks source link

EntityMap NPE #59

Closed odwrotnie closed 11 years ago

odwrotnie commented 11 years ago

There is a problem with createEntity when there are some unset fields. Even if they have default values.

odwrotnie commented 11 years ago

The next NPE is while updatingEntity:

Message: java.lang.NullPointerException
    net.fwbrasil.activate.entity.EntityMap$$anonfun$updateEntity$2.apply(EntityMap.scala:72)
    net.fwbrasil.activate.entity.EntityMap$$anonfun$updateEntity$2.apply(EntityMap.scala:66)
    scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
    scala.collection.immutable.HashMap$HashMap1.foreach(HashMap.scala:224)
    scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:403)
    scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
    net.fwbrasil.activate.entity.EntityMap.updateEntity(EntityMap.scala:66)
    net.fwbrasil.activate.lift.EntityForm.net$fwbrasil$activate$lift$EntityForm$$super$updateEntity(EntityForm.scala:27)
    net.fwbrasil.activate.lift.EntityForm$$anonfun$updateEntity$1.apply(EntityForm.scala:27)
    net.fwbrasil.activate.lift.EntityForm$$anonfun$updateEntity$1.apply(EntityForm.scala:27)
    net.fwbrasil.activate.lift.EntityForm.translateInvariantsExceptions(EntityForm.scala:31)
    net.fwbrasil.activate.lift.EntityForm.updateEntity(EntityForm.scala:26)
    net.fwbrasil.activate.entity.EntityMap$$anonfun$tryUpdate$2.apply(EntityMap.scala:36)
    net.fwbrasil.activate.entity.EntityMap$$anonfun$tryUpdate$2.apply(EntityMap.scala:36)
    scala.Option.map(Option.scala:145)
    net.fwbrasil.activate.entity.EntityMap.tryUpdate(EntityMap.scala:36)
    net.fwbrasil.activate.entity.EntityMap.updateEntity(EntityMap.scala:33)
    tasks.snippet.TaskDetails$$anonfun$render$6$$anonfun$apply$8.apply(TaskDetails.scala:32)
    tasks.snippet.TaskDetails$$anonfun$render$6$$anonfun$apply$8.apply(TaskDetails.scala:31)
    net.liftweb.http.S$NFuncHolder$$anonfun$apply$4.apply(S.scala:185)
    net.liftweb.http.S$NFuncHolder$$anonfun$apply$4.apply(S.scala:185)
    scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    scala.collection.immutable.List.foreach(List.scala:318)
    scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    scala.collection.AbstractTraversable.map(Traversable.scala:105)
    net.liftweb.http.S$NFuncHolder.apply(S.scala:185)
    net.liftweb.http.S$ProxyFuncHolder.apply(S.scala:114)
    net.liftweb.http.LiftSession$$anonfun$net$liftweb$http$LiftSession$$buildFunc$1$2.apply(LiftSession.scala:765)
    net.liftweb.http.LiftSession$$anonfun$21$$anonfun$apply$37.apply(LiftSession.scala:779)
    net.liftweb.http.LiftSession$$anonfun$21$$anonfun$apply$37.apply(LiftSession.scala:779)
    scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    scala.collection.immutable.List.foreach(List.scala:318)
    scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    scala.collection.AbstractTraversable.map(Traversable.scala:105)
    net.liftweb.http.LiftSession$$anonfun$21.apply(LiftSession.scala:779)
    net.liftweb.http.LiftSession$$anonfun$21.apply(LiftSession.scala:770)
    scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    scala.collection.immutable.List.foreach(List.scala:318)
    scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
    scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
    net.liftweb.http.LiftSession.runParams(LiftSession.scala:769)
    net.liftweb.http.LiftSession.processRequest(LiftSession.scala:1216)
    net.liftweb.http.LiftServlet.net$liftweb$http$LiftServlet$$dispatchStatefulRequest(LiftServlet.scala:423)
    net.liftweb.http.LiftServlet$$anonfun$doSession$1$1.apply(LiftServlet.scala:301)
    net.liftweb.http.LiftServlet$$anonfun$doSession$1$1.apply(LiftServlet.scala:301)
    net.liftweb.http.S$class.net$liftweb$http$S$$wrapQuery(S.scala:1460)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1$$anonfun$apply$37.apply(S.scala:1625)
    net.liftweb.http.S$class.net$liftweb$http$S$$doAround(S.scala:1389)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$doAround$1.apply(S.scala:1390)
    bootstrap.liftweb.Boot$$anon$1$$anonfun$1.apply(Boot.scala:50)
    bootstrap.liftweb.Boot$$anon$1$$anonfun$1.apply(Boot.scala:49)
    net.fwbrasil.radon.transaction.TransactionManager.runInTransaction(TransactionManager.scala:53)
    net.fwbrasil.radon.transaction.TransactionManager.runInTransactionWithRetry(TransactionManager.scala:69)
    net.fwbrasil.radon.transaction.TransactionManager.runInNewTransactionWithRetry(TransactionManager.scala:62)
    net.fwbrasil.radon.transaction.Required.execute(Propagation.scala:26)
    net.fwbrasil.radon.transaction.TransactionContext$class.transactional(TransactionContext.scala:47)
    model.Context$.transactional(Context.scala:9)
    net.fwbrasil.radon.transaction.TransactionContext$class.transactional(TransactionContext.scala:26)
    model.Context$.transactional(Context.scala:9)
    transaction.Transaction$.apply(Transaction.scala:8)
    bootstrap.liftweb.Boot$$anon$1.apply(Boot.scala:48)
    net.liftweb.http.S$class.net$liftweb$http$S$$doAround(S.scala:1390)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1.apply(S.scala:1623)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$class.net$liftweb$http$S$$_nest2InnerInit(S.scala:1622)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun$apply$41$$anonfun$apply$42$$anonfun$apply$43$$anonfun$apply$44.apply(S.scala:1666)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$withReq$1.apply(S.scala:1676)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$class.withReq(S.scala:1675)
    net.liftweb.http.S$.withReq(S.scala:47)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun$apply$41$$anonfun$apply$42$$anonfun$apply$43.apply(S.scala:1662)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun$apply$41$$anonfun$apply$42.apply(S.scala:1660)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun$apply$41.apply(S.scala:1659)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1.apply(S.scala:1658)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$class.net$liftweb$http$S$$_innerInit(S.scala:1657)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1$$anonfun$apply$47$$anonfun$apply$48$$anonfun$apply$49$$anonfun$apply$50$$anonfun$apply$51.apply(S.scala:1699)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1$$anonfun$apply$47$$anonfun$apply$48$$anonfun$apply$49$$anonfun$apply$50.apply(S.scala:1697)
    net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:613)
    net.liftweb.http.RequestVarHandler$.apply(Vars.scala:515)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1$$anonfun$apply$47$$anonfun$apply$48$$anonfun$apply$49.apply(S.scala:1696)
    net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:613)
    net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:528)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1$$anonfun$apply$47$$anonfun$apply$48.apply(S.scala:1695)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1$$anonfun$apply$47.apply(S.scala:1694)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_init$1.apply(S.scala:1693)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.S$class.net$liftweb$http$S$$_init(S.scala:1692)
    net.liftweb.http.S$class.init(S.scala:1274)
    net.liftweb.http.S$.init(S.scala:47)
    net.liftweb.http.LiftServlet.doSession$1(LiftServlet.scala:300)
    net.liftweb.http.LiftServlet.doService(LiftServlet.scala:310)
    net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:148)
    net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:147)
    net.liftweb.util.TimeHelpers$class.calcTime(TimeHelpers.scala:345)
    net.liftweb.util.Helpers$.calcTime(Helpers.scala:34)
    net.liftweb.util.TimeHelpers$class.logTime(TimeHelpers.scala:364)
    net.liftweb.util.Helpers$.logTime(Helpers.scala:34)
    net.liftweb.http.LiftServlet.doIt$1(LiftServlet.scala:147)
    net.liftweb.http.LiftServlet.service(LiftServlet.scala:158)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply$mcV$sp(HTTPProvider.scala:72)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply(HTTPProvider.scala:71)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply(HTTPProvider.scala:71)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.URLRewriter$.doWith(Req.scala:1278)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply$mcV$sp(HTTPProvider.scala:70)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:70)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:70)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply$mcV$sp(HTTPProvider.scala:66)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:60)
    net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:60)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.provider.HTTPProvider$class.service(HTTPProvider.scala:60)
    net.liftweb.http.LiftFilter.service(LiftServlet.scala:928)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply$mcV$sp(ServletFilterProvider.scala:82)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply(ServletFilterProvider.scala:82)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1$$anonfun$apply$mcV$sp$2.apply(ServletFilterProvider.scala:82)
    net.liftweb.http.provider.servlet.ServletFilterProvider$class.handleLoan$1(ServletFilterProvider.scala:59)
    net.liftweb.http.provider.servlet.ServletFilterProvider$class.net$liftweb$http$provider$servlet$ServletFilterProvider$$handleLoanWrappers(ServletFilterProvider.scala:63)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(ServletFilterProvider.scala:82)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:77)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:77)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15$$anonfun$apply$16$$anonfun$apply$17.apply(Vars.scala:619)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15$$anonfun$apply$16.apply(Vars.scala:618)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15.apply(Vars.scala:617)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14.apply(Vars.scala:616)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:615)
    net.liftweb.http.RequestVarHandler$.apply(Vars.scala:515)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply$mcV$sp(ServletFilterProvider.scala:75)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:75)
    net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:75)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15$$anonfun$apply$16$$anonfun$apply$17.apply(Vars.scala:619)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15$$anonfun$apply$16.apply(Vars.scala:618)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14$$anonfun$apply$15.apply(Vars.scala:617)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$14.apply(Vars.scala:616)
    net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
    net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:615)
    net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:528)
    net.liftweb.http.provider.servlet.ServletFilterProvider$class.doFilter(ServletFilterProvider.scala:74)
    net.liftweb.http.LiftFilter.doFilter(LiftServlet.scala:928)
    org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
    org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
    org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:559)
    org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
    org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
    org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
    org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    org.eclipse.jetty.server.Server.handle(Server.java:361)
    org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
    org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
    org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
    org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
    org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
    org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
    org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    java.lang.Thread.run(Thread.java:724)
fwbrasil commented 11 years ago

I can't reproduce the error here. A possible problem is that the entity map is of a class different from the class of the entity to be updated. Could you verify this possibility?

odwrotnie commented 11 years ago

It is the same class.

The code works fine when I replace:

val taskEF = new EntityForm[Task](task)

with:

val taskEF = new EntityForm[Task](
    _.deadline -> task.deadline,
    _.description -> task.description)
fwbrasil commented 11 years ago

I reproduced the problem in your application. The error was due an entity enhance problem with private lazy val inside a "super" trait, in you case commons.logger.Logger.logger.

FIxed, please sbt update. :)

odwrotnie commented 11 years ago

Thank you!