[ 
https://issues.apache.org/jira/browse/BEANUTILS-417?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099458#comment-18099458
 ] 

René Zanner edited comment on BEANUTILS-417 at 7/27/26 2:40 PM:
----------------------------------------------------------------

Added a pull request [430|https://github.com/apache/commons-beanutils/pull/430] 
for the proposed change including an additional unit test using Wildfly 
{{ObjectCloner}} (which was failing on our end with the newest 1.x and 2.x 
versions).

{{DynaProperty}} is not following the Java Language Specification: 
{{in.defaultReadObject}}/{{out.defaultWriteObject}} must be called first inside 
of {{readObject}}/{{writeObject}} [1][2].

Here's a stacktrace that shows the Wildfly {{ObjectCloner}} checking this and 
failing:
{code}
java.lang.IllegalStateException: defaultWriteObject may not be called in this 
context
        at 
org.jboss.marshalling.cloner.SerializingCloner$StepObjectOutputStream.defaultWriteObject(SerializingCloner.java:612)
        at 
org.apache.commons.beanutils.DynaProperty.writeObject(DynaProperty.java:336)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)
        at 
org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:297)
        at 
org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:251)
        at 
org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:128)
        at 
org.jboss.marshalling.cloner.SerializingCloner$StepObjectInput.doReadObject(SerializingCloner.java:882)
        ...
{code}

[1] 
https://docs.oracle.com/en/java/javase/11/docs/specs/serialization/input.html#the-readobject-method
[2] 
https://docs.oracle.com/en/java/javase/11/docs/specs/serialization/output.html#the-writeobject-method


was (Author: rzanner):
Added a pull request [429|https://github.com/apache/commons-beanutils/pull/429] 
for the proposed change including an additional unit test using Wildfly 
{{ObjectCloner}} (which was failing on our end with the newest 1.x and 2.x 
versions).

{{DynaProperty}} is not following the Java Language Specification: 
{{in.defaultReadObject}}/{{out.defaultWriteObject}} must be called first inside 
of {{readObject}}/{{writeObject}} [1][2].

Here's a stacktrace that shows the Wildfly {{ObjectCloner}} checking this and 
failing:
{code}
java.lang.IllegalStateException: defaultWriteObject may not be called in this 
context
        at 
org.jboss.marshalling.cloner.SerializingCloner$StepObjectOutputStream.defaultWriteObject(SerializingCloner.java:612)
        at 
org.apache.commons.beanutils.DynaProperty.writeObject(DynaProperty.java:336)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)
        at 
org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:297)
        at 
org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:251)
        at 
org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:128)
        at 
org.jboss.marshalling.cloner.SerializingCloner$StepObjectInput.doReadObject(SerializingCloner.java:882)
        ...
{code}

[1] 
https://docs.oracle.com/en/java/javase/11/docs/specs/serialization/input.html#the-readobject-method
[2] 
https://docs.oracle.com/en/java/javase/11/docs/specs/serialization/output.html#the-writeobject-method

> java.io.StreamCorruptedException: defaultWriteObject or writeFields not 
> called on the sender's side
> ---------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-417
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-417
>             Project: Commons BeanUtils
>          Issue Type: Bug
>         Environment: WebSphere Platform 7.0.0.23 [ND 7.0.0.23 cf231218.02] 
> Host Operating System is Linux, version 2.6.32.59-0.7-default
> Java version = JRE 1.6.0 IBM J9 2.4 Linux amd64-64 
> jvmxa6460sr10fp1-20120202_101568 (JIT enabled, AOT enabled)
> J9VM - 20120202_101568
> JIT  - r9_20111107_21307ifx1
> GC   - 20120202_AA_CMPRSS, Java Compiler = j9jit24, Java VM name = IBM J9 VM
>            Reporter: krisha
>            Priority: Blocker
>             Fix For: 2.0.0-M2
>
>         Attachments: BEANUTILS-417.patch
>
>
> The exception is an expected behavior as the implementation of the    
> DynaProperty.readObject and DynaProperty.writeObject do not adhere to 
> the serialization specifications.                                     
> When I looked at the implementation of the write/readObject in           
> org.apache.commons.beanutils.DynaProperty at the link -                  
> (                                                                        
> http://javasourcecode.org/html/open-source/commons-beanutils/commons-bea 
> nutils-1.8.1/org/apache/commons/beanutils/DynaProperty.java.html)        
> I see that they do not adhere to the serialization specification         
> (                                                                        
> http://docs.oracle.com/javase/7/docs/platform/serialization/spec/output. 
> html#861)                                                                
> which states the following -                                             
> Either ObjectOutputStream's defaultWriteObject or writeFields method     
> must be called once (and only once) before writing any optional data     
> that will be needed by the corresponding readObject method to restore    
> the state of the object; even if no optional data is written,            
> defaultWriteObject or writeFields must still be invoked once. If         
> defaultWriteObject or writeFields is not invoked once prior to the       
> writing of optional data (if any), then the behavior of instance         
> deserialization is undefined in cases where the ObjectInputStream cannot 
> resolve the class which defined the writeObject method in question.      
> ------------------------------------------------------------------------ 
> The defaultWriteObject or writeFields have to be invoked prior to        
> writing any data.                                                        
>                                                                          
> A fix was added to the Java 6 SR10 onwards (IX90079), to catch incorrect 
> implementations of the read/writeObjects. Hence, the exception is seen   
> with WAS 7.                                                              
> 3182 [8/24/12 12:13:45:967 EDT] 00000034 ORBRas        3 
> com.ibm.rmi.io.IIOPInputStream invokeObjectReader:1812 ORB.thread.pool : 0 
> The following exception was logged
> 3183                                  
> java.lang.reflect.InvocationTargetException
> 3184  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 3185  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
> 3186  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 3187  at java.lang.reflect.Method.invoke(Method.java:600)
> 3188  at 
> com.ibm.rmi.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1809)
> 3189  at 
> com.ibm.rmi.io.IIOPInputStream.inputObjectUsingClassDesc(IIOPInputStream.java:1529)
> 3190  at 
> com.ibm.rmi.io.IIOPInputStream.inputObjectClassDesc(IIOPInputStream.java:1504)
> 3191  at 
> com.ibm.rmi.io.IIOPInputStream.readSerializable(IIOPInputStream.java:1178)
> 3192  at 
> com.ibm.rmi.io.IIOPInputStream.simpleReadObjectInternal(IIOPInputStream.java:460)
> 3193  at 
> com.ibm.rmi.io.IIOPInputStream.simpleReadObjectLoop(IIOPInputStream.java:545)
> 3194  at 
> com.ibm.rmi.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:497)
> 3195  at com.ibm.rmi.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:210)
> 3196  at com.ibm.rmi.iiop.CDRReader.read_value(CDRReader.java:1578)
> 3197  at 
> com.ibm.rmi.iiop.ObjectCopierFactory$AbstractArrayCopier.doWork(ObjectCopierFactory.java:424)
> 3198  at 
> com.ibm.rmi.iiop.ObjectCopierFactory$AbstractCopier.invoke(ObjectCopierFactory.java:229)
> 3199  at $Proxy24.doWork(Unknown Source)
> 3200  at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
> 3201  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1613)
> 3202 Caused by: java.io.StreamCorruptedException: defaultWriteObject or 
> writeFields not called on the sender's side
> 3203  at 
> com.ibm.rmi.io.IIOPInputStream.defaultReadObject(IIOPInputStream.java:681)
> 3204  at 
> org.apache.commons.beanutils.DynaProperty.readObject(DynaProperty.java:281)
> 3205  ... 18 more



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to