Cyr*_* N. 5 java-7 playframework playframework-2.0
这是我的模型文档:
@Entity
@Table(name = "documents")
public class Document extends Model {
@Id
public Long id;
@Constraints.Required
@Formats.NonEmpty
@Column(nullable=false)
public String document;
public static Model.Finder<Long,Document> find = new Model.Finder(Long.class, Document.class);
// Will return an absolute URL to this document
public String getUrl() {
return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,它在编译时抛出了一个VerifyError异常,并且我发现唯一要避免它的是,对该行进行注释并将其替换为return null; =>不是很有效:/
这是该异常的堆栈跟踪:
Caused by: java.lang.VerifyError: Bad type on operand stack in method models.Document.getUrl()Ljava/lang/String; at offset 13
at java.lang.Class.forName0(Native Method) ~[na:1.7.0_05]
at java.lang.Class.forName(Class.java:264) ~[na:1.7.0_05]
at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:69) ~[play_2.9.1.jar:2.0.2]
Run Code Online (Sandbox Code Playgroud)
这个错误是什么?如何在不丢失getUrl方法的情况下避免它?
谢谢你的帮助!
我认为 Ebean 正试图在这里施展一些魔法。
我建议使用静态函数:
public static String buildUrl(String document) {
return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}
Run Code Online (Sandbox Code Playgroud)