如果尝试添加JsonPut&而无法编译代码RestHelper类中的JsonPost方法具有相同的路径

时间:2012-05-26 03:05:36

标签: java scala lift

我正在尝试添加JsonPut& RestHelper类中的JsontPost方法,具有与bellow相同的路径:

object MembershipAPI extends RestHelper with LogHelper {
  serve {
    case JsonPost("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
      () => Full(GroupMembershipController.Join(group_id, user_id, request))
    case JsonPut("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
      () => Full(GroupMembershipController.Join(group_id, user_id, request))
    case JsonDelete("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
      () => Full(GroupMembershipController.Leave(group_id, user_id, request))
  }
}

当运行sbt compile时,我收到此错误:

java.lang.Error: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511
    at ch.epfl.lamp.fjbg.JFieldOrMethod.writeTo(JFieldOrMethod.java:130)
    at ch.epfl.lamp.fjbg.JClass.writeTo(JClass.java:358)
    at scala.tools.nsc.backend.jvm.BytecodeWriters$ClassBytecodeWriter$class.writeClass(BytecodeWriters.scala:87)
    at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anon$2.writeClass(GenJVM.scala:82)
    at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.emitClass(GenJVM.scala:172)
    at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:304)
    at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
    at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
    at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
    at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
    at scala.collection.Iterator$class.foreach(Iterator.scala:652)
    at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
    at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
    at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:43)
    at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:102)
    at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:949)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1034)
    at xsbt.CompilerInterface.run(CompilerInterface.scala:81)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at xsbt.AnalyzingCompiler.call(AnalyzingCompiler.scala:40)
    at xsbt.AnalyzingCompiler.apply(AnalyzingCompiler.scala:18)
    at sbt.Compile.processScala(Compile.scala:76)
    at sbt.CompilerCore$$anonfun$1.apply(Compile.scala:27)
    at sbt.CompilerCore$$anonfun$1.apply(Compile.scala:27)
    at sbt.CompilerCore$$anonfun$process$1$1.apply(Compile.scala:22)
    at sbt.CompilerCore$$anonfun$process$1$1.apply(Compile.scala:22)
    at sbt.CompilerCore$$anonfun$doCompile$3.apply(Compile.scala:45)
    at sbt.CompilerCore$$anonfun$doCompile$3.apply(Compile.scala:42)
    at scala.Option.orElse(Option.scala:102)
    at sbt.CompilerCore.doCompile(Compile.scala:41)
    at sbt.CompilerCore.apply(Compile.scala:29)
    at sbt.AbstractCompileConditional.run$1(Conditional.scala:341)
    at sbt.AbstractCompileConditional$$anonfun$3.apply(Conditional.scala:344)
    at sbt.AbstractCompileConditional$$anonfun$3.apply(Conditional.scala:344)
    at sbt.classfile.Analyze$.apply(Analyze.scala:110)
    at sbt.AbstractCompileConditional.execute(Conditional.scala:344)
    at sbt.Conditional$class.run(Conditional.scala:43)
    at sbt.AbstractCompileConditional.run(Conditional.scala:231)
    at sbt.BasicScalaProject.sbt$BasicScalaProject$$doCompile(DefaultProject.scala:260)
    at sbt.BasicScalaProject$$anonfun$compileAction$1.apply(DefaultProject.scala:274)
    at sbt.BasicScalaProject$$anonfun$compileAction$1.apply(DefaultProject.scala:274)
    at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
    at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
    at sbt.impl.RunTask.runTask(RunTask.scala:85)
    at sbt.impl.RunTask.run(RunTask.scala:32)
    at sbt.impl.RunTask$.apply(RunTask.scala:17)
    at sbt.impl.RunTask$.apply(RunTask.scala:16)
    at sbt.Project$class.run(Project.scala:98)
    at sbt.Project$class.act(Project.scala:129)
    at sbt.BasicScalaProject.act(DefaultProject.scala:21)
    at sbt.xMain$$anonfun$8.apply(Main.scala:530)
    at sbt.xMain$$anonfun$8.apply(Main.scala:530)
    at sbt.xMain.withAction(Main.scala:563)
    at sbt.xMain.sbt$xMain$$handleAction(Main.scala:530)
    at sbt.xMain.handleCommand(Main.scala:520)
    at sbt.xMain.processAction(Main.scala:459)
    at sbt.xMain.process$1(Main.scala:257)
    at sbt.xMain.processArguments(Main.scala:266)
    at sbt.xMain.startProject(Main.scala:107)
    at sbt.xMain.run(Main.scala:84)
    at sbt.xMain.run0$1(Main.scala:35)
    at sbt.xMain.run(Main.scala:42)
    at xsbt.boot.Launch$.run(Launch.scala:53)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$.launch(Launch.scala:57)
    at xsbt.boot.Launch$.explicit(Launch.scala:42)
    at xsbt.boot.Launch$.initialized(Launch.scala:38)
    at xsbt.boot.Launch$.parsed(Launch.scala:31)
    at xsbt.boot.Launch$.configured(Launch.scala:21)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Launch$.apply(Launch.scala:13)
    at xsbt.boot.Boot$.runImpl(Boot.scala:24)
    at xsbt.boot.Boot$.run(Boot.scala:19)
    at xsbt.boot.Boot$.main(Boot.scala:15)
    at xsbt.boot.Boot.main(Boot.scala)
Caused by: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511
    at ch.epfl.lamp.fjbg.JCode.checkOffset16(JCode.java:903)
    at ch.epfl.lamp.fjbg.JCode.patchAllOffset(JCode.java:982)
    at ch.epfl.lamp.fjbg.JCode.freeze(JCode.java:102)
    at ch.epfl.lamp.fjbg.JMethod.freeze(JMethod.java:89)
    at ch.epfl.lamp.fjbg.JFieldOrMethod.writeTo(JFieldOrMethod.java:127)
    ... 79 more
Error during sbt execution: java.lang.Error: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511

我不知道为什么会这样,怎么解决这个问题?

提前谢谢!

1 个答案:

答案 0 :(得分:3)

创建的部分函数对于Scala编译器来说太大了。它是带有scala编译器的issue

要解决此问题,您需要将选择器分解为多个服务语句。因此,只需找到一个存在逻辑中断的位置并创建两个RestHelper函数。

例如,

object MembershipAPIOne extends RestHelper with LogHelper {
  serve {
   case JsonPost("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request)    =>
   () => Full(GroupMembershipController.Join(group_id, user_id, request))
   case JsonPut("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
  () => Full(GroupMembershipController.Join(group_id, user_id, request))
  }
 }

object MembershipAPITwo extends RestHelper with LogHelper {
  serve {
case JsonDelete("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
  () => Full(GroupMembershipController.Leave(group_id, user_id, request))
 }
}

有关更多帮助,请参阅http://www.assembla.com/spaces/liftweb/wiki/REST_Web_Services