2D ベクトルを表す非常に単純な Java クラスがあります。しかし、コードを実行してメッセージ パックにシリアル化すると、実行時エラーが発生します。このクラスをシリアル化することは、本当に基本的な動作であり、機能するはずですよね? 同様の問題を抱えている人は他にいませんでした。
コードと例外は以下のとおりです。Windows 7 の Eclipse で Java 1.7 SDK を使用しており、Maven からメッセージ パック 1.6.6 および 1.6.7 を試しました。
import org.jbox2d.common.Vec2;
import org.msgpack.annotation.Message;
@Message
public class SerVec2
{
public float x,y;
public SerVec2(Vec2 v)
{
this.x = v.x;
this.y = v.y;
}
public Vec2 toV()
{
return new Vec2(x,y);
}
}
void someWhereElse(SerVec2 sv)
{
MessagePack msgpack = new MessagePack();
byte[] bytes = msgpack.write(sv);
}
実行時エラー:
Feb 18, 2013 8:48:49 AM org.msgpack.template.builder.BuildContext build
SEVERE: builder:
{
if (!$3 && $1.trySkipNil()) {
return null;
}
skylights.util.SerVec2 _$$_t;
if ($2 == null) {
_$$_t = new skylights.util.SerVec2();
} else {
_$$_t = (skylights.util.SerVec2) $2;
}
$1.readArrayBegin();
_$$_t.x = $1.readFloat();
_$$_t.y = $1.readFloat();
$1.readArrayEnd();
return _$$_t;
}
org.msgpack.MessageTypeException: org.msgpack.template.builder.TemplateBuildException: Cannot compile:
{
if (!$3 && $1.trySkipNil()) {
return null;
}
skylights.util.SerVec2 _$$_t;
if ($2 == null) {
_$$_t = new skylights.util.SerVec2();
} else {
_$$_t = (skylights.util.SerVec2) $2;
}
$1.readArrayBegin();
_$$_t.x = $1.readFloat();
_$$_t.y = $1.readFloat();
$1.readArrayEnd();
return _$$_t;
}
at org.msgpack.template.TemplateRegistry.buildAndRegister(TemplateRegistry.java:516)
at org.msgpack.template.TemplateRegistry.lookupAfterBuilding(TemplateRegistry.java:413)
at org.msgpack.template.TemplateRegistry.lookup(TemplateRegistry.java:246)
at org.msgpack.template.builder.JavassistTemplateBuilder.toTemplate(JavassistTemplateBuilder.java:128)
at org.msgpack.template.builder.JavassistTemplateBuilder.buildTemplate(JavassistTemplateBuilder.java:116)
at org.msgpack.template.builder.AbstractTemplateBuilder.buildTemplate(AbstractTemplateBuilder.java:61)
at org.msgpack.template.TemplateRegistry.buildAndRegister(TemplateRegistry.java:503)
at org.msgpack.template.TemplateRegistry.lookupAfterBuilding(TemplateRegistry.java:413)
at org.msgpack.template.TemplateRegistry.lookup(TemplateRegistry.java:246)
at org.msgpack.MessagePack.write(MessagePack.java:195)
at skylights.core.Entity.saveToBytes(Entity.java:260)
at skylights.level.Level.saveToFile(Level.java:106)
at skylights.core.gui.KeyHandler.keyPressed(KeyHandler.java:29)
at skylights.core.Game.keyPressed(Game.java:219)
at org.newdawn.slick.Input.poll(Input.java:1182)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:656)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at skylights.core.Game.run(Game.java:264)
at skylights.core.Game.main(Game.java:287)
Caused by: org.msgpack.template.builder.TemplateBuildException: Cannot compile:
{
if (!$3 && $1.trySkipNil()) {
return null;
}
skylights.util.SerVec2 _$$_t;
if ($2 == null) {
_$$_t = new skylights.util.SerVec2();
} else {
_$$_t = (skylights.util.SerVec2) $2;
}
$1.readArrayBegin();
_$$_t.x = $1.readFloat();
_$$_t.y = $1.readFloat();
$1.readArrayEnd();
return _$$_t;
}
at org.msgpack.template.builder.BuildContext.build(BuildContext.java:73)
at org.msgpack.template.builder.DefaultBuildContext.buildTemplate(DefaultBuildContext.java:56)
at org.msgpack.template.builder.JavassistTemplateBuilder.buildTemplate(JavassistTemplateBuilder.java:118)
at org.msgpack.template.builder.AbstractTemplateBuilder.buildTemplate(AbstractTemplateBuilder.java:61)
at org.msgpack.template.TemplateRegistry.buildAndRegister(TemplateRegistry.java:503)
... 19 more
Caused by: javassist.CannotCompileException: [source error] no such constructor
at javassist.CtBehavior.setBody(CtBehavior.java:417)
at javassist.CtBehavior.setBody(CtBehavior.java:383)
at javassist.CtNewMethod.make(CtNewMethod.java:138)
at org.msgpack.template.builder.BuildContext.buildReadMethod(BuildContext.java:144)
at org.msgpack.template.builder.BuildContext.build(BuildContext.java:65)
... 23 more
Caused by: compile error: no such constructor
at javassist.compiler.MemberCodeGen.atMethodCallCore2(MemberCodeGen.java:593)
at javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java:575)
at javassist.compiler.MemberCodeGen.atNewExpr(MemberCodeGen.java:302)
at javassist.compiler.ast.NewExpr.accept(NewExpr.java:73)
at javassist.compiler.CodeGen.atAssignCore(CodeGen.java:860)
at javassist.compiler.CodeGen.atVariableAssign(CodeGen.java:793)
at javassist.compiler.CodeGen.atAssignExpr(CodeGen.java:747)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:332)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:391)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:292)
at javassist.compiler.Javac.compileBody(Javac.java:223)
at javassist.CtBehavior.setBody(CtBehavior.java:409)
... 27 more