mnimer / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

NPE on Serialization #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi all,

First of all, thanks to everyone involved for the effort going into this
much needed project. 

I'm not sure if I'm missing something or if this is indeed a bug: I'm
getting a NullPointerException during serialization in response to a call
to a Spring bean; otherwise, the call to the method in question appears to
be successful.

Attached is complete source code for a (small) Eclipse project designed to
test lazy loading with dpHibernate. The only changes required to run the
code are to modify the database settings (in
WEB-INF/spring/applicationContext-db.xml and hibernate/hibernate.cfg.xml)
and add a test record to the "Parent" table.

Please let me know if you have any questions.

Thanks,
James

Environment: Flex 3, dpHibernate 1.0.9, BlazeDS 3.0, Spring Framework
2.0.8, Hibernate 3.2.1, and JBoss 4.2.2 GA.

Log/stack trace:

20:18:12,664 INFO  [STDOUT] [BlazeDS] FlexSession created with id
'9067E7720D96A6214AF2F33B2A3B708F' for an Http-based client connection.
20:18:12,671 INFO  [STDOUT] [BlazeDS] Channel endpoint my-amf received request.
20:18:12,817 INFO  [STDOUT] [BlazeDS] Deserializing AMF/HTTP request
Version: 3
  (Message #0 targetURI=null, responseURI=/1)
    (Array #0)
      [0] = (Typed Object #0 'flex.messaging.messages.CommandMessage')
        operation = 5
        correlationId = ""
        messageId = "CAC7F09E-73A1-93F2-B851-3730551D9AB5"
        timeToLive = 0
        timestamp = 0
        body = (Object #1)
        headers = (Object #2)
          DSMessagingVersion = 1
          DSId = "nil"
        clientId = null
        destination = ""
20:18:12,868 INFO  [STDOUT] [BlazeDS] Serializing AMF/HTTP response
Version: 3
  (Message #0 targetURI=/1/onResult, responseURI=)
    (Externalizable Object #0 'DSK')
      (Object #1)
        DSId = "BD09134A-0E77-FFE8-35F7-6980B9F083FB"
        DSMessagingVersion = 1.0
1.212106692843E12
(Byte Array #2, Length 16)
(Byte Array #3, Length 16)
(Byte Array #4, Length 16)
20:18:13,023 INFO  [STDOUT] [BlazeDS] Channel endpoint my-amf received request.
20:18:13,045 INFO  [STDOUT] [BlazeDS] Deserializing AMF/HTTP request
Version: 3
  (Message #0 targetURI=null, responseURI=/2)
    (Array #0)
      [0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage')
        operation = "getParentById"
        source = null
        messageId = "596D8E73-0105-F098-4FFF-3730547F3A8C"
        timeToLive = 0
        timestamp = 0
        body = (Array #1)
          [0] = 1
        headers = (Object #2)
          DSEndpoint = "my-amf"
          DSId = "BD09134A-0E77-FFE8-35F7-6980B9F083FB"
        clientId = null
        destination = "parentService"
20:18:13,175 INFO  [STDOUT] Hibernate: 
    /* load test.model.Parent */ select
        parent0_.id as id28_0_,
        parent0_.name as name28_0_ 
    from
        Parent parent0_ 
    where
        parent0_.id=?
20:18:13,180 INFO  [STDOUT] Parent name: test
20:18:13,303 ERROR [STDERR] java.lang.NullPointerException
20:18:13,304 ERROR [STDERR]     at
net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.writeB
ean(HibernateSerializer.java:183)
20:18:13,305 ERROR [STDERR]     at
net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.transl
ate(HibernateSerializer.java:124)
20:18:13,306 ERROR [STDERR]     at
net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.transl
ate(HibernateSerializer.java:87)
20:18:13,307 ERROR [STDERR]     at
net.digitalprimates.persistence.hibernate.HibernateAdapter.invoke(HibernateAdapt
er.java:181)
20:18:13,307 ERROR [STDERR]     at
flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
20:18:13,308 ERROR [STDERR]     at
flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1417)
20:18:13,308 ERROR [STDERR]     at
flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:8
78)
20:18:13,309 ERROR [STDERR]     at
flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java
:121)
20:18:13,309 ERROR [STDERR]     at
flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
20:18:13,310 ERROR [STDERR]     at
flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:49)
20:18:13,311 ERROR [STDERR]     at
flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:6
7)
20:18:13,311 ERROR [STDERR]     at
flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java
:146)
20:18:13,311 ERROR [STDERR]     at
flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:274)
20:18:13,312 ERROR [STDERR]     at
flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:377)
20:18:13,312 ERROR [STDERR]     at
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
20:18:13,313 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:290)
20:18:13,313 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:206)
20:18:13,313 ERROR [STDERR]     at
net.digitalprimates.persistence.hibernate.utils.filters.HibernateSessionServletF
ilter.doFilter(HibernateSessionServletFilter.java:62)
20:18:13,314 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:235)
20:18:13,314 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:206)
20:18:13,315 ERROR [STDERR]     at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:9
6)
20:18:13,315 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:235)
20:18:13,315 ERROR [STDERR]     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:206)
20:18:13,316 ERROR [STDERR]     at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2
30)
20:18:13,316 ERROR [STDERR]     at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1
75)
20:18:13,316 ERROR [STDERR]     at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociatio
nValve.java:179)
20:18:13,317 ERROR [STDERR]     at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
20:18:13,317 ERROR [STDERR]     at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
20:18:13,318 ERROR [STDERR]     at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
20:18:13,319 ERROR [STDERR]     at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionVa
lve.java:157)
20:18:13,320 ERROR [STDERR]     at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109
)
20:18:13,320 ERROR [STDERR]     at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
20:18:13,321 ERROR [STDERR]     at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
20:18:13,321 ERROR [STDERR]     at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Pr
otocol.java:583)
20:18:13,322 ERROR [STDERR]     at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
20:18:13,322 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:613)
20:18:13,324 INFO  [STDOUT] [BlazeDS] Adapter 'hibernate-object' called
'parentService.getParentById(java.util.Arrays$ArrayList (Collection size:1)
  [0] = 1
)'
20:18:13,325 INFO  [STDOUT] [BlazeDS] Result: 'null'
20:18:13,328 INFO  [STDOUT] [BlazeDS] Serializing AMF/HTTP response
Version: 3
  (Message #0 targetURI=/2/onResult, responseURI=)
    (Externalizable Object #0 'DSK')
      1.212106693326E12
(Byte Array #1, Length 16)
(Byte Array #2, Length 16)
(Byte Array #3, Length 16)
20:48:53,982 INFO  [STDOUT] [BlazeDS] FlexSession with id
'9067E7720D96A6214AF2F33B2A3B708F' for an Http-based client connection has
been invalidated.

Original issue reported on code.google.com by jmcl...@matrixlinks.ca on 30 May 2008 at 2:03

Attachments:

GoogleCodeExporter commented 9 years ago
Changing line 182 of HibernateSerializer.java from:

if (!"class".equals(propName) && !"annotations".equals(propName) &&
!"hibernateLazyInitializer".equals(propName))

to:

if (!"handler".equals(propName) && !"class".equals(propName) &&
!"annotations".equals(propName) && !"hibernateLazyInitializer".equals(propName))

solves the problem.

Original comment by jmcl...@matrixlinks.ca on 30 May 2008 at 4:38

GoogleCodeExporter commented 9 years ago
James,
thanks for the bug and the solution! I just checked it as buikd 1.0.11. Can you 
confirm that this fixes it for you?

Thanks,
--mike

Original comment by mni...@gmail.com on 30 May 2008 at 8:51

GoogleCodeExporter commented 9 years ago
I solved this problem changing the IF clause like this at 
HibernateSerializer.java
and HibernateDeserializer.java:

if (!"handler".equals(propName) && !"class".equals(propName) 
&& !"annotations".equals(propName) 
&& !"hibernateLazyInitializer".equals(propName)
&& !"defaultAssertionStatus".equals(propName) && !"workDir".equals(propName)).

Another point is that you have to check about IndexedPropertyDescriptor at 
readBean()
on HibernateDeserializer.java method like this to avoid NPE:

if(pd instanceof IndexedPropertyDescriptor) {
  val = ((IndexedPropertyDescriptor) pd).getIndexedReadMethod().invoke(obj);
} else {
  val = pd.getReadMethod().invoke(obj);
}

I also added a check about collection types at readCollection() method on
HibernateSerializer.java and HibernateDeserializer.java to instantiate any type 
of
collection, not only List with ArrayList:
            if("java.util.Arrays$ArrayList".equals(obj.getClass().getName())) {
    items = new ArrayList();
} else {
    items = (Collection<Object>) obj.getClass().newInstance();

}

I hope that it fixes your problem.

Original comment by dfalca...@gmail.com on 10 Mar 2010 at 2:50