gusgogar / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

NullPointerException Thrown By cacheQueryResults Method in StreamingQueryResult #301

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Running version 1.7.2 of the AppEngine.  When closing an extent, the 
com.google.appengine.datanucleus.query.StreamingQueryResult.cacheQueryResults 
class encounters a NullPointerException.

java.lang.NullPointerException
    at com.google.appengine.datanucleus.query.StreamingQueryResult.cacheQueryResults(StreamingQueryResult.java:116)
    at com.google.appengine.datanucleus.query.StreamingQueryResult.closeResults(StreamingQueryResult.java:109)
    at org.datanucleus.store.query.AbstractQueryResult.close(AbstractQueryResult.java:143)
    at org.datanucleus.store.query.Query.close(Query.java:2124)
    at org.datanucleus.store.query.Query.closeAll(Query.java:2139)
    at org.datanucleus.store.DefaultCandidateExtent.closeAll(DefaultCandidateExtent.java:97)
    at org.datanucleus.api.jdo.JDOExtent.closeAll(JDOExtent.java:66)
    at com.wildstartech.justocrm.jdo.BaseDAOImpl.getAll(BaseDAOImpl.java:293)
    at com.wildstartech.justocrm.ui.IssueListForm.<init>(IssueListForm.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:148)
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
    at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
    at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:413)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1773)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.wildstartech.justocrm.appengine.AuthenticationCheck.doFilter(AuthenticationCheck.java:61)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:370)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

The following is the method of my class in which the exception was invoked by 
line 293 which simply calls extent.closeAll();

252 public List<K> getAll() {
253    logger.entering(_CLASS, "getAll()");
254           Class<P> persistentClass = null;
255      Extent<P> extent = null;
256      List<K> objects = null;
257      PersistenceManager pm = null;
258      Transaction transaction = null;
259      pm = getPersistenceManager();
260      /*
261       * Indicate all objects returned by the PersistenceManager are to be
262       * detached when the transaction is committed.
263       */
264      pm.setDetachAllOnCommit(true);
265      /*
266       * Return all instances of the UserImpl class WITHOUT returning any
267       * subclasses.
268       */
269      try {
270         persistentClass = getPersistentClass();
271         transaction = pm.currentTransaction();
272         // Begin the transaction
273         transaction.begin();
274         extent = pm.getExtent(persistentClass, false);
275         // Create an ArrayList to hold the results.
276         objects = new ArrayList<K>();
277         // Go through the extent and add the objects to the array.
278         for (P object : extent) {
279            // Add the user object to the array.
280           objects.add((K) object);
281         } // END for (UserImpl user: extent)
282         // Commit the transaction.
283         transaction.commit();
284      } catch (JDOException ex) {
285         // Some type of exception was thrown.
286         logger.log(Level.SEVERE, "JDOException thrown getting ALL users.", 
ex);
287         // Roll the transaction back
288         transaction.rollback();
289      } finally {
290         // Close the Extent
291         if (extent != null) {
292             try {
293               extent.closeAll();
294            } catch (NullPointerException ex) {
295               logger.log(Level.WARNING,"NullPointerException thrown.",ex);
296            } // END try/catch
297         } // END if (extent != null)
298         // Close the transaction if it is open
299         if (transaction.isActive()) {
300         // Roll the transaction back
301         transaction.rollback();
302      } // END if (transaction.isActive())
303      // Close the PersistenceManager
304      if (pm != null) {
305         pm.close();
306      } // END if (pm != null)
307   } // END try/catch
308   logger.exiting(_CLASS, "getAll()", objects);
309   return objects;
310 }

Original issue reported on code.google.com by derek.berube on 21 Sep 2012 at 1:54

GoogleCodeExporter commented 9 years ago
There is a single object loaded in the extent.  I have wrapped the 
extent.closeAll() method call with a try/catch block that grabs and logs the 
NullPointerException so my application can continue to run.

Original comment by derek.berube on 21 Sep 2012 at 2:01

GoogleCodeExporter commented 9 years ago
Also caused when I invoke the closeAll() method on a Query object.

Caused by: java.lang.NullPointerException
    at com.google.appengine.datanucleus.query.StreamingQueryResult.cacheQueryResults(StreamingQueryResult.java:116)
    at com.google.appengine.datanucleus.query.StreamingQueryResult.closeResults(StreamingQueryResult.java:109)
    at org.datanucleus.store.query.AbstractQueryResult.close(AbstractQueryResult.java:143)
    at org.datanucleus.store.query.Query.close(Query.java:2124)
    at org.datanucleus.store.query.Query.closeAll(Query.java:2139)
    at org.datanucleus.api.jdo.JDOQuery.closeAll(JDOQuery.java:85)
    at com.wildstartech.justocrm.jdo.GroupDAOImpl.findByName(GroupDAOImpl.java:106)
    at com.wildstartech.justocrm.jdo.GroupDAOImpl.findByName(GroupDAOImpl.java:1)
    at com.wildstartech.justocrm.ui.BasicTicketForm.setAssignedGroupName(BasicTicketForm.java:82)
    at com.wildstartech.justocrm.ui.IssueEditorForm.<init>(IssueEditorForm.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:148)
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)

Original comment by derek.berube on 21 Sep 2012 at 2:34

GoogleCodeExporter commented 9 years ago
To eliminate the NullPointerException, I modified the cacheQueryResults() 
method of the StreamingQueryResult class found in the 
com.google.appengine.datanucleus.query package from the following:

protected void cacheQueryResults() {
    if (query.useResultsCaching()) {
          lazyResult.resolveAll();
          query.getQueryManager().addDatastoreQueryResult(query, query.getInputParameters(), lazyResult.getEntityKeys());
    }   
}

to the following:

protected void cacheQueryResults() {
    if (query != null) {
        if (query.useResultsCaching()) {
            lazyResult.resolveAll();
            query.getQueryManager().addDatastoreQueryResult(query, query.getInputParameters(), lazyResult.getEntityKeys());
        }
    } // END if (query != null)
}

Original comment by derek.berube on 21 Sep 2012 at 3:27

GoogleCodeExporter commented 9 years ago
Current SVN trunk likely works, left as an exercise to check it

Original comment by googleco...@yahoo.co.uk on 27 Sep 2012 at 11:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
We are getting this exception too on calling query.closeAll(). We are currently 
using the latest dist version 2.0. How do we get the latest fix?

Original comment by amit.san...@gmail.com on 17 Oct 2012 at 4:14

GoogleCodeExporter commented 9 years ago
Any guidance as to when the 2.1.2 version of the 
datanucleus-appengine-2.1.2.jar is going to be formerly released?

Original comment by derek.be...@wildstartech.com on 11 Nov 2012 at 5:39

GoogleCodeExporter commented 9 years ago
You get the latest fix by checking out from SVN of this project and typing "mvn 
clean install". When its released is for Google to decide ...

Original comment by googleco...@yahoo.co.uk on 26 Nov 2012 at 9:14