DWR Bug Report (NullPointerException, Minor /w fix)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DWR Bug Report (NullPointerException, Minor /w fix)

ememisya
Dear DWR Development Team,

I'm getting the following NullPointerException warning when destroying
the test context using Spring:

WARN : org.springframework.beans.factory.support.DisposableBeanAdapter -
Invocation of destroy method failed on bean with name 'dwrController':
java.lang.NullPointerException

Version: 3.0.0-rc3-RELEASE
SHA1 Checksum:  c2fd542b646157cf847c1b642eee30e3949a98b4

I define the Controller as follows:

<dwr:controller id="dwrController" debug="true" />

I traced the issue to DefaultCreatorManager @ line 203 - 230

     /* (non-Javadoc)
      * @see
org.directwebremoting.extend.UninitializingBean#contextDestroyed()
      */
     public void contextDestroyed()
     {
         WebContext webcx = WebContextFactory.get();
         for(Creator c : creators.values()) {
             if (c.getScope().equals(Creator.APPLICATION)) {
                 Object creatorInstance =
webcx.getServletContext().getAttribute(c.getJavascript());
                 if (creatorInstance instanceof UninitializingBean) {
                     ((UninitializingBean)
creatorInstance).contextDestroyed();
                 }
             }
         }
     }

     /* (non-Javadoc)
      * @see
org.directwebremoting.extend.UninitializingBean#servletDestroyed()
      */
     public void servletDestroyed()
     {
         WebContext webcx = WebContextFactory.get();
         for(Creator c : creators.values()) {
             if (c.getScope().equals(Creator.APPLICATION)) {
                 Object creatorInstance =
webcx.getServletContext().getAttribute(c.getJavascript());
                 if (creatorInstance instanceof UninitializingBean) {
                     ((UninitializingBean)
creatorInstance).servletDestroyed();
                 }
             }
         }
     }

 From the code snippet above, the NullPointerException occurs at:

Object creatorInstance = webcx.getServletContext()...

The reason for this is that WebContextFactory.get() allows for null to
return, however the DefaultCreatorManager doesn't test for null.

Simply adding:

if (webcx != null && webcx.getServletContext() != null) {

  ....

}

Would fix the issue.  Thank you for your consideration.

Sincerely,

--Erdem "Adam" Memisyazici

-VT-Middleware

[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: DWR Bug Report (NullPointerException, Minor /w fix)

Mike Wilson
Administrator
Thanks for the report! I'll look into it.

Best regards
Mike Wilson

John Doe wrote:

> Dear DWR Development Team,
>
> I'm getting the following NullPointerException warning when
> destroying
> the test context using Spring:
>
> WARN :
> org.springframework.beans.factory.support.DisposableBeanAdapter -
> Invocation of destroy method failed on bean with name
> 'dwrController':
> java.lang.NullPointerException
>
> Version: 3.0.0-rc3-RELEASE
> SHA1 Checksum:  c2fd542b646157cf847c1b642eee30e3949a98b4
>
> I define the Controller as follows:
>
> <dwr:controller id="dwrController" debug="true" />
>
> I traced the issue to DefaultCreatorManager @ line 203 - 230
>
>      /* (non-Javadoc)
>       * @see
> org.directwebremoting.extend.UninitializingBean#contextDestroyed()
>       */
>      public void contextDestroyed()
>      {
>          WebContext webcx = WebContextFactory.get();
>          for(Creator c : creators.values()) {
>              if (c.getScope().equals(Creator.APPLICATION)) {
>                  Object creatorInstance =
> webcx.getServletContext().getAttribute(c.getJavascript());
>                  if (creatorInstance instanceof UninitializingBean) {
>                      ((UninitializingBean)
> creatorInstance).contextDestroyed();
>                  }
>              }
>          }
>      }
>
>      /* (non-Javadoc)
>       * @see
> org.directwebremoting.extend.UninitializingBean#servletDestroyed()
>       */
>      public void servletDestroyed()
>      {
>          WebContext webcx = WebContextFactory.get();
>          for(Creator c : creators.values()) {
>              if (c.getScope().equals(Creator.APPLICATION)) {
>                  Object creatorInstance =
> webcx.getServletContext().getAttribute(c.getJavascript());
>                  if (creatorInstance instanceof UninitializingBean) {
>                      ((UninitializingBean)
> creatorInstance).servletDestroyed();
>                  }
>              }
>          }
>      }
>
>  From the code snippet above, the NullPointerException occurs at:
>
> Object creatorInstance = webcx.getServletContext()...
>
> The reason for this is that WebContextFactory.get() allows
> for null to
> return, however the DefaultCreatorManager doesn't test for null.
>
> Simply adding:
>
> if (webcx != null && webcx.getServletContext() != null) {
>
>   ....
>
> }
>
> Would fix the issue.  Thank you for your consideration.
>
> Sincerely,
>
> --Erdem "Adam" Memisyazici
>
> -VT-Middleware
>
> [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DWR Bug Report (NullPointerException, Minor /w fix)

Mike Wilson
Administrator
This seems to be an oversight from our side. The WebContext should
normally be set when arriving at the cleanup/destroy logic so I
have instead fixed the Spring integration container.

I have created:
https://directwebremoting.atlassian.net/browse/DWR-629
where you can also find a new build to try out.
 
Best regards
Mike

Mike Wilson wrote:

> Thanks for the report! I'll look into it.
>
> Best regards
> Mike Wilson
>
> John Doe wrote:
> > Dear DWR Development Team,
> >
> > I'm getting the following NullPointerException warning when
> > destroying
> > the test context using Spring:
> >
> > WARN :
> > org.springframework.beans.factory.support.DisposableBeanAdapter -
> > Invocation of destroy method failed on bean with name
> > 'dwrController':
> > java.lang.NullPointerException
> >
> > Version: 3.0.0-rc3-RELEASE
> > SHA1 Checksum:  c2fd542b646157cf847c1b642eee30e3949a98b4
> >
> > I define the Controller as follows:
> >
> > <dwr:controller id="dwrController" debug="true" />
> >
> > I traced the issue to DefaultCreatorManager @ line 203 - 230
> >
> >      /* (non-Javadoc)
> >       * @see
> > org.directwebremoting.extend.UninitializingBean#contextDestroyed()
> >       */
> >      public void contextDestroyed()
> >      {
> >          WebContext webcx = WebContextFactory.get();
> >          for(Creator c : creators.values()) {
> >              if (c.getScope().equals(Creator.APPLICATION)) {
> >                  Object creatorInstance =
> > webcx.getServletContext().getAttribute(c.getJavascript());
> >                  if (creatorInstance instanceof
> UninitializingBean) {
> >                      ((UninitializingBean)
> > creatorInstance).contextDestroyed();
> >                  }
> >              }
> >          }
> >      }
> >
> >      /* (non-Javadoc)
> >       * @see
> > org.directwebremoting.extend.UninitializingBean#servletDestroyed()
> >       */
> >      public void servletDestroyed()
> >      {
> >          WebContext webcx = WebContextFactory.get();
> >          for(Creator c : creators.values()) {
> >              if (c.getScope().equals(Creator.APPLICATION)) {
> >                  Object creatorInstance =
> > webcx.getServletContext().getAttribute(c.getJavascript());
> >                  if (creatorInstance instanceof
> UninitializingBean) {
> >                      ((UninitializingBean)
> > creatorInstance).servletDestroyed();
> >                  }
> >              }
> >          }
> >      }
> >
> >  From the code snippet above, the NullPointerException occurs at:
> >
> > Object creatorInstance = webcx.getServletContext()...
> >
> > The reason for this is that WebContextFactory.get() allows
> > for null to
> > return, however the DefaultCreatorManager doesn't test for null.
> >
> > Simply adding:
> >
> > if (webcx != null && webcx.getServletContext() != null) {
> >
> >   ....
> >
> > }
> >
> > Would fix the issue.  Thank you for your consideration.
> >
> > Sincerely,
> >
> > --Erdem "Adam" Memisyazici
> >
> > -VT-Middleware
> >
> > [hidden email]
>