I’m using JDK 7 and testing Play! 1.2.4. I was creating a test class with a public member called ‘name’ and got the exception that my class was overriding final method ‘getName’:
public class DummyClass extends Thread {
public String name;
...
}
This class is not really part of the “framework” itself: it is a Thread that receives info from a Socket and stores it in a Database through Play! JPA object (from the “models” package).
My application is not a full “Web app” but has some parts which should be accessed through a browser (typically: configuration, simple Database search, …). It is running a @OnApplicationStart Job which launches Threads, Sockets, saves files, …
I’m guessing Play! automatically generates getters and setters but it looks like it is also changing my own classes.
I’m not sure if this is a “bug” of the framework or if I just misunderstood the concept and need to change a few things (at least, renaming ‘name’ into ‘dummyName’ does the trick! :))?
Here is the Stack trace:
play.exceptions.UnexpectedException: Unexpected Error
at play.Invoker$Invocation.onException(Invoker.java:244)
at play.Invoker$Invocation.run(Invoker.java:286)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.VerifyError: class com.deepgray.acq.Acquisition overrides final method getName.()Ljava/lang/String;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:166)
at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at play.classloading.ApplicationClasses.getAssignableClasses(ApplicationClasses.java:67)
at play.classloading.ApplicationClassloader.getAssignableClasses(ApplicationClassloader.java:455)
at play.templates.GroovyTemplateCompiler.endTag(GroovyTemplateCompiler.java:342)
at play.templates.TemplateCompiler.generate(TemplateCompiler.java:93)
at play.templates.TemplateCompiler.compile(TemplateCompiler.java:15)
at play.templates.GroovyTemplateCompiler.compile(GroovyTemplateCompiler.java:41)
at play.templates.TemplateCompiler.compile(TemplateCompiler.java:28)
at play.templates.TemplateLoader.load(TemplateLoader.java:82)
at play.mvc.Router.parse(Router.java:162)
at play.mvc.Router.parse(Router.java:190)
at play.mvc.Router.parse(Router.java:164)
at play.mvc.Router.load(Router.java:48)
at play.mvc.Router.detectChanges(Router.java:219)
... 1 more
Yes, the problem you have here is that you have a public member, which the play ‘magic’ is generating setters and getters for you.
Simply changing the member name will solve your issue. I don’t think this is a bug, because Play expects to enhance these classes. I am not sure if it should be restricted to certain packages, because it is a general expectation that all public members are made accessible in this way.