Bad type on the operand stack in method models. My model

Here is my Document model:

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

The problem is that it throws a VerifyError exception at compile time, and the only thing I found to avoid this was to comment out the line and replace it with return null; => Not very effective: /

Here's the stack trace for this exception:

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]

What is this error and how to avoid it without losing the getUrl method?

Thank you for your help!

+5
source share
3 answers

I think Ebean is trying to do some magic here.

I suggest using a static function:

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

you can just add

@Transient

annotation to the method and it works!

+3
source

I had the same problem today. I tried to apply the same logic suggested above (use a static function for the problem method), but to no avail. I restarted the game, removed, recompiled, and the problem disappeared.

Here are the playback commands that I used.

exit
play
clean
run
+1
source

All Articles