方法models.MyModel中操作数堆栈上的错误类型

时间:2012-08-11 09:22:13

标签: playframework playframework-2.0 java-7

这是我的模型文档:

@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());
    }
}

问题是,它在编译时抛出了一个VerifyError异常,而我发现唯一要避免它的是,对该行进行注释并将其替换为return null; =&GT;不是很有效:/

以下是该例外的堆栈跟踪:

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]

这是什么错误,如何在不丢失getUrl方法的情况下避免错误?

感谢您的帮助!

3 个答案:

答案 0 :(得分:4)

我认为Ebean正试图在这里做一些魔术。

我建议使用静态函数:

public static String buildUrl(String document) {
    return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}

答案 1 :(得分:3)

你可以添加

@Transient

注释方法,它有效!

答案 2 :(得分:1)

今天我遇到了同样的问题。我尝试应用上面建议的相同逻辑(对问题方法使用静态函数)但无济于事。我重新开始播放,清理,重新编译,问题就消失了。

以下是我使用的播放命令。

exit
play
clean
run