PropertiesEnhancer throwing a NPE on startup

60 views
Skip to first unread message

wyz

unread,
Jun 10, 2010, 6:52:16 AM6/10/10
to play-framework
Hi,

I have faced a strange issue with play. There is a UnexpectedError
caused by NPE when I first start up, however the application will run
as normal if I refresh it and the error is gone. My environment is
Ubuntu 10.04 64bit and Sun Java 6. The whole stacktrace is attached,
and any help will be appreciated.

Thanks.


Oops: UnexpectedException
An unexpected error occured caused by exception UnexpectedException:
Error in PropertiesEnhancer

play.exceptions.UnexpectedException: While applying class
play.classloading.enhancers.PropertiesEnhancer on
search.FullTextSearchPlugin
at play.classloading.ApplicationClasses
$ApplicationClass.enhance(ApplicationClasses.java:211)
at
play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:
125)
at
play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:
74)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at play.Play.start(Play.java:341)
at play.Play.detectChanges(Play.java:492)
at play.Invoker$Invocation.init(Invoker.java:98)
at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: Error in
PropertiesEnhancer
at play.classloading.enhancers.PropertiesEnhancer
$1.edit(PropertiesEnhancer.java:139)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:197)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtBehavior.instrument(CtBehavior.java:618)
at
play.classloading.enhancers.PropertiesEnhancer.enhanceThisClass(PropertiesEnhancer.java:
100)
at play.classloading.ApplicationClasses
$ApplicationClass.enhance(ApplicationClasses.java:208)
... 7 more
Caused by: java.lang.NullPointerException
at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)
at play.classloading.enhancers.Enhancer
$ApplicationClassesClasspath.openClassfile(Enhancer.java:60)
at javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:335)
at javassist.ClassPool.openClassfile(ClassPool.java:594)
at javassist.CtClassType.getClassFile2(CtClassType.java:185)
at javassist.CtClassType.makeFieldCache(CtClassType.java:760)
at javassist.CtClassType.getMembers(CtClassType.java:751)
at javassist.CtClassType.getDeclaredField2(CtClassType.java:873)
at javassist.CtClassType.getField2(CtClassType.java:828)
at javassist.CtClassType.getField(CtClassType.java:820)
at javassist.expr.FieldAccess.getField(FieldAccess.java:113)
at play.classloading.enhancers.PropertiesEnhancer
$1.edit(PropertiesEnhancer.java:107)
... 12 more

Guillaume Bort

unread,
Jun 10, 2010, 7:23:15 AM6/10/10
to play-fr...@googlegroups.com
I think that it is an old issue already fixed. What is your play version?

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

wyz

unread,
Jun 10, 2010, 10:41:35 PM6/10/10
to play-framework
I am running 1.0.2.1

Guillaume Bort

unread,
Jun 11, 2010, 11:53:43 AM6/11/10
to play-fr...@googlegroups.com
Well I don't know. Never saw that. Can you send me a simple app that
reproduce it?

wyz

unread,
Jun 16, 2010, 3:17:55 AM6/16/10
to play-framework
I have tested with play 1.0.3 and the problem persists.

I tried to create a simple app to reproduce it but failed. I am not
able to give you my current project, but I am able to give you more
informations.

1. I have created a plugin called FullTextSearchPlugin, and I
configured it as "20:search.FullTextSearchPlugin" in play.plugins
2. Inside the FullTextSearchPlugin, I imported another class
"models.TagSubject"
3. The NPE is caused at line 60 in class Enhancer, it reads "new
ByteArrayInputStream(Play.classes.getApplicationClass(className).enhancedByteCode);"
4. At the time, className is "models.TagSubject",
Play.classes.getApplicationClass(className) evaluates to
"models.TagSubject (compiled:false) " and
Play.classes.getApplicationClass(className).enhancedByteCode is null,
which caused the NPE

Hope these information will help. Thanks.


On Jun 11, 11:53 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Well I don't know. Never saw that. Can you send me a simple app that
> reproduce it?
>
>
>
> On Fri, Jun 11, 2010 at 4:41 AM,wyz<wangyiz...@gmail.com> wrote:
> > I am running 1.0.2.1
>
> > On Jun 10, 7:23 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> >> I think that it is an old issue already fixed. What is your play version?
>

Guillaume Bort

unread,
Jun 16, 2010, 4:54:34 AM6/16/10
to play-fr...@googlegroups.com
Please show me the code of the plugin. There is surely something bad
in the lifecycle.

Tony Xiao

unread,
Apr 14, 2011, 5:30:53 AM4/14/11
to play-fr...@googlegroups.com
I also run into this very same issue in Play 1.2.  Here's the code from the Plugin (still work in progress, lots of snippets experimenting everywhere. ) Basically I didn't like how JPA binds model objects and tried to intercept it myself.  But on class start i would get some exceptions. 

package com.tulsi.binders;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Map;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import models.BaseModel;
import models.autoup.IB;

import play.Logger;
import play.PlayPlugin;
import play.data.binding.BeanWrapper;

public class TulsiBinderPlugin extends PlayPlugin {

public static BeanWrapper ibWrapper = new BeanWrapper(IB.class);

@Override
public Object bind(String name, Class clazz, Type type,
Annotation[] annotations, Map<String, String[]> params) {
// debug(name, clazz, type, annotations, params);
Class sc = clazz.getSuperclass();
if (sc != null && sc.getCanonicalName().equals(BaseModel.class.getCanonicalName())) {
Logger.debug("BaseModel intercepted by TulsiBinder");
if (clazz.getName().equals(IB.class.getName()))
return bindIB(name, type, annotations, params);
}

// if (clazz.getName().equals(models.autoup.IB.class.getName())) {
// IB i = new IB();
// i.contractId =2323232;
// return i;
// IB i = IB.all().first();
// return i;
// }
return null;
}

public IB bindIB(String name, Type type,
Annotation[] annotations, Map<String, String[]> params) {

IB ib;
try {
ib = (IB) ibWrapper.bind(name, type, params, "", annotations);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
ib = new IB();
}
//new IB();
ib.localSymbol = "";
for (String key : params.keySet()) {
ib.localSymbol += key + "\n";
ib.localSymbol += "\t" + Arrays.asList(params.get(key)) + "\n";
}
if (params.get("ib") != null) {
JSONObject obj = (JSONObject) JSONValue.parse(params.get("ib")[0]);
ib.localSymbol += "\n json object starts here\n\n";
ib.localSymbol += obj.toJSONString();
}

        if (true)
return ib;
        Field fieldlist[] = IB.class.getDeclaredFields();
        for (int i = 0; i < fieldlist.length; i++) {
           Field fld = fieldlist[i];
           System.out.println("name = " + fld.getName());
           System.out.println("decl class = " + fld.getDeclaringClass());
           System.out.println("type = " + fld.getType());
           int mod = fld.getModifiers();
           System.out.println("modifiers = " + Modifier.toString(mod));
           System.out.println("-----");
        }
return null;
}

private void debug(String name, Class clazz, Type type,
Annotation[] annotations, Map<String, String[]> params) {
System.out.println("Name : " + name );
System.out.println(type.getClass());
System.out.println(clazz.getSuperclass());
for (String key : params.keySet()) {
System.out.println(key);
System.out.println(Arrays.asList(params.get(key)));
}
System.out.println("annotations");
System.out.println(Arrays.asList(annotations));
}
}


Oops: UnexpectedException
An unexpected error occured caused by exception UnexpectedException: While applying class play.classloading.enhancers.Pr
opertiesEnhancer on com.tulsi.binders.TulsiBinderPlugin

play.exceptions.UnexpectedException: While applying play.CorePlugin@317cfd38 on com.tulsi.binders.TulsiBinderPlugin
        at play.plugins.PluginCollection.enhance(PluginCollection.java:436)
        at play.classloading.ApplicationClasses$ApplicationClass.enhance(ApplicationClasses.java:208)
        at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:151)
        at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at play.plugins.PluginCollection.reloadApplicationPlugins(PluginCollection.java:141)
        at play.Play.start(Play.java:418)
        at play.Play.detectChanges(Play.java:569)
        at play.Invoker$Invocation.init(Invoker.java:186)
        at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: While applying class play.classloading.enhancers.PropertiesEnhancer on c
om.tulsi.binders.TulsiBinderPlugin
        at play.CorePlugin.enhance(CorePlugin.java:297)
        at play.plugins.PluginCollection.enhance(PluginCollection.java:433)
        ... 9 more
Caused by: play.exceptions.UnexpectedException: Error in PropertiesEnhancer
        at play.classloading.enhancers.PropertiesEnhancer$1.edit(PropertiesEnhancer.java:171)
        at javassist.expr.ExprEditor.loopBody(ExprEditor.java:197)
        at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
        at javassist.CtBehavior.instrument(CtBehavior.java:618)
        at play.classloading.enhancers.PropertiesEnhancer.enhanceThisClass(PropertiesEnhancer.java:129)
        at play.CorePlugin.enhance(CorePlugin.java:294)
        ... 10 more
Caused by: java.lang.NullPointerException
        at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)
        at play.classloading.enhancers.Enhancer$ApplicationClassesClasspath.openClassfile(Enhancer.java:60)
        at javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:335)
        at javassist.ClassPool.openClassfile(ClassPool.java:594)
        at javassist.CtClassType.getClassFile2(CtClassType.java:185)
        at javassist.CtClassType.makeFieldCache(CtClassType.java:760)
        at javassist.CtClassType.getMembers(CtClassType.java:751)
        at javassist.CtClassType.getDeclaredField2(CtClassType.java:873)
        at javassist.CtClassType.getField2(CtClassType.java:828)
        at javassist.CtClassType.getField(CtClassType.java:820)
        at javassist.expr.FieldAccess.getField(FieldAccess.java:113)
        at play.classloading.enhancers.PropertiesEnhancer$1.edit(PropertiesEnhancer.java:136)
        ... 15 more

robfig

unread,
Apr 14, 2011, 11:47:11 AM4/14/11
to play-fr...@googlegroups.com
I have run into very similar errors when I accidentally had duplicate .class files in Play!'s classpath.  You may want to ensure that there is exactly one TulsiBinderPlugin.class file ..

The second thing I would try is making ibWrapper not a static member (e.g. creating a new one for every invocation), just to see if that makes the error go away.
(public static BeanWrapper ibWrapper = new BeanWrapper(IB.class);)


Reply all
Reply to author
Forward
0 new messages