Quantcast

NPE in beforeDelete

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

NPE in beforeDelete

Paweł Gdula-2
Hello!

I have problem with NPE in beforeDelete event handler. BeforeDelete is created by AST transformation. It was tested in simple scaffolding controller. In integration tests there is no such error, only in live env with mysql db. Field "biImage" in container object is created by AST transformation too. Saving and updating of Foo object is working well - just this delete action is problematic. 


My stacktrace:

    
Caused by: java.lang.NullPointerException
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
at org.hibernate.collection.PersistentMap.isEmpty(PersistentMap.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at pl.burningice.plugins.image.container.DbContainerWorker.hasImage(DbContainerWorker.groovy:14)


Code:


class DeleteDbImageCommand {
    static public void execute(DBImageContainer container){
        Image.withNewSession {
            new DbContainerWorker(container:container).delete()
        }
    }
}

-------------------------------

class DbContainerWorker extends ContainerWorker {

    boolean hasImage() {
        return (container.biImage != null
                  && !container.biImage.isEmpty())      <== NPE is throw here
    }

    void delete() {
        if (!hasImage()){
            return
        }
        container.biImage.collect {it.value}.each {it.delete()}
        container.biImage = null
    }

    SaveCommand getSaveCommand(String size) {
        return new SaveToDbCommand(container, size)
    }
}

-------------------------------

class Foo {

     Map biImage

def beforeDelete() {
DeleteDbImageCommand.execute(this) }
}



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: NPE in beforeDelete

Paweł Gdula-2
Anyone?

On 6 June 2010 13:56, Paweł Gdula <[hidden email]> wrote:
Hello!

I have problem with NPE in beforeDelete event handler. BeforeDelete is created by AST transformation. It was tested in simple scaffolding controller. In integration tests there is no such error, only in live env with mysql db. Field "biImage" in container object is created by AST transformation too. Saving and updating of Foo object is working well - just this delete action is problematic. 


My stacktrace:

    
Caused by: java.lang.NullPointerException
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
at org.hibernate.collection.PersistentMap.isEmpty(PersistentMap.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at pl.burningice.plugins.image.container.DbContainerWorker.hasImage(DbContainerWorker.groovy:14)


Code:


class DeleteDbImageCommand {
    static public void execute(DBImageContainer container){
        Image.withNewSession {
            new DbContainerWorker(container:container).delete()
        }
    }
}

-------------------------------

class DbContainerWorker extends ContainerWorker {

    boolean hasImage() {
        return (container.biImage != null
                  && !container.biImage.isEmpty())      <== NPE is throw here
    }

    void delete() {
        if (!hasImage()){
            return
        }
        container.biImage.collect {it.value}.each {it.delete()}
        container.biImage = null
    }

    SaveCommand getSaveCommand(String size) {
        return new SaveToDbCommand(container, size)
    }
}

-------------------------------

class Foo {

     Map biImage

def beforeDelete() {
DeleteDbImageCommand.execute(this) }
}




Loading...