Dec 23, 2010

java.lang.VerifyError caused by Play-Morphia

It comes out intermittently and shows something like:
Exception in thread "main" java.lang.VerifyError: (class: models/NodeDelta, method: findById signature: (Ljava/lang/Object;)Lplay/modules/morphia/Model;) Wrong return type in function
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at com.google.code.morphia.utils.ReflectionUtils.getDeclaredAndInheritedMethods(ReflectionUtils.java:115)
at com.google.code.morphia.utils.ReflectionUtils.getDeclaredAndInheritedMethods(ReflectionUtils.java:98)
at com.google.code.morphia.mapping.MappedClass.discover(MappedClass.java:131)
at com.google.code.morphia.mapping.MappedClass.(MappedClass.java:110)
at com.google.code.morphia.mapping.Mapper.addMappedClass(Mapper.java:139)
at com.google.code.morphia.Morphia.map(Morphia.java:55)
at play.modules.morphia.MorphiaPlugin.afterApplicationStart(MorphiaPlugin.java:166)
at play.Play.start(Play.java:440)
at play.Play.init(Play.java:274)
at play.server.Server.main(Server.java:131)

Something is wrong obviously in the bytecode enhancer. But I just can't figure it out until i noticed the line of code:
CtMethod findById = CtMethod.make("public static Model findById(java.lang.Object id) { return mf.findById(id); }",ctClass);

Where mf is an instance of play.db.Model.Factory, and method play.db.Model.Factory#findById return an instance of play.db.Model, while actually a play.modules.morphia.Model is expected. Changing the line to the follows fixed the VerifyError:
CtMethod findById = CtMethod.make("public static Model findById(java.lang.Object id) {return (Model)mf.findById(id); }",ctClass);

No comments:

About Me

My photo