Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad type on operand stack in method models.MyModel

Here's my model Document :

@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, it throws a VerifyError exception at compile time, and the only thing I found to avoid it, is comment the line and replace it with return null, which is not very effective.

Here's the stack trace for that 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 can I avoid it without losing the getUrl method?

like image 940
Cyril N. Avatar asked Aug 11 '12 09:08

Cyril N.


3 Answers

I think Ebean is trying to do some magic here.

I suggest to use a static function:

public static String buildUrl(String document) {
    return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}
like image 173
ndeverge Avatar answered Nov 11 '22 18:11

ndeverge


you can just add

@Transient

annotation to method and it works!

like image 22
quester Avatar answered Nov 11 '22 17:11

quester


I had this 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 play, cleaned, recompiled, and the problem went away.

Here are the play commands I used.

exit
play
clean
run
like image 31
Wade Anderson Avatar answered Nov 11 '22 17:11

Wade Anderson