Forum Stats

  • 3,768,030 Users
  • 2,252,744 Discussions
  • 7,874,414 Comments

Discussions

Using viewScope for Bean giving NotSerializableException

User_PGA0I
User_PGA0I Member Posts: 32 Red Ribbon

JDeveloper Version: Studio Edition Version 12.2.1.3.0

We are using requestScope for most of our Beans in the Taskflows, however due to few issues we are using viewScope for few of the Beans for our Application in ADF. Few questions:

1) Does viewScope have any issues.

2) Can we use pageFlowScope as a replacement to get rid of these issues.


For the Taskflows that have viewScope for the Beans, we are seeing following Exception in the logs.

<Nov 19, 2021 3:49:33,516 PM EST> <Error> <oracle.adfinternal.controller.state.SessionBasedScopeMap> <ADFC-62004> <ADFc: Scope object serialization failed (object not serializable), scope='viewScope[/WEB-INF/gov/pa/sers/seris/view/common/common/journals/checkjournal/flow/CheckJournalTF.xml#[email protected]]', objectKey='currRowAttrMap', objectType='java.util.HashMap'.> 

<Nov 19, 2021 3:49:33,516 PM EST> <Error> <oracle.adfinternal.controller.state.SessionBasedScopeMap> <BEA-000000> <

java.io.NotSerializableException: oracle.jbo.server.ViewRowImpl

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at java.util.HashMap.internalWriteEntries(HashMap.java:1785)

at java.util.HashMap.writeObject(HashMap.java:1362)

at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at oracle.adfinternal.controller.util.Utils.verifySerializableCheck(Utils.java:395)

at oracle.adfinternal.controller.util.Utils.verifySerializable(Utils.java:383)

at oracle.adfinternal.controller.state.SessionBasedScopeMap.writeScopeMap(SessionBasedScopeMap.java:159)

at oracle.adfinternal.controller.state.ViewScope.writeObject(ViewScope.java:95)

at sun.reflect.GeneratedMethodAccessor846.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1413)

at sun.reflect.GeneratedMethodAccessor136.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at weblogic.servlet.internal.session.ReplicatedSessionChange.writeMapKeysAndValuesToStream(ReplicatedSessionChange.java:234)

at weblogic.servlet.internal.session.ReplicatedSessionChange.writeExternal(ReplicatedSessionChange.java:202)

at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at weblogic.cluster.replication.WrappedSerializable.writeExternal(WrappedSerializable.java:23)

at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

at weblogic.rjvm.MsgAbbrevOutputStream.writeObject(MsgAbbrevOutputStream.java:674)

at weblogic.rjvm.MsgAbbrevOutputStream.writeObjectWL(MsgAbbrevOutputStream.java:666)

at weblogic.rmi.internal.ObjectIO.writeObject(ObjectIO.java:38)

at weblogic.rjvm.BasicOutboundRequest.marshalArgs(BasicOutboundRequest.java:96)

at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:297)

at weblogic.cluster.replication.RemoteReplicationServicesInternalImpl_12213_WLStub.update(Unknown Source)

at sun.reflect.GeneratedMethodAccessor792.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at weblogic.cluster.replication.SecureReplicationInvocationHandler$ReplicationServicesInvocationAction.run(SecureReplicationInvocationHandler.java:222)

at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)

at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:137)

at weblogic.cluster.replication.SecureReplicationInvocationHandler.invoke(SecureReplicationInvocationHandler.java:192)

at com.sun.proxy.$Proxy258.update(Unknown Source)

at weblogic.cluster.replication.ReplicationServicesImplBase.sendUpdateRequestToSecondary(ReplicationServicesImplBase.java:1670)

at weblogic.cluster.replication.ReplicationServicesImplBase.updateSecondaryInternal(ReplicationServicesImplBase.java:1559)

at weblogic.cluster.replication.ReplicationServicesImplBase.updateSecondary(ReplicationServicesImplBase.java:1525)

at weblogic.cluster.replication.ReplicationServicesImplBase.updateSecondary(ReplicationServicesImplBase.java:1520)

at weblogic.servlet.internal.session.ReplicatedSessionData._syncSession(ReplicatedSessionData.java:741)

at weblogic.servlet.internal.session.ReplicatedSessionData.syncSession(ReplicatedSessionData.java:705)

at weblogic.servlet.internal.session.SessionContext.sync(SessionContext.java:161)

at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.syncSession(ServletRequestImpl.java:3447)

at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.syncSessions(ServletRequestImpl.java:3425)

at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.syncSession(ServletRequestImpl.java:3413)

at weblogic.servlet.internal.ServletResponseImpl$1.run(ServletResponseImpl.java:1811)

at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)

at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)

at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)

at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)

at weblogic.servlet.internal.ServletResponseImpl.syncSession(ServletResponseImpl.java:1807)

at weblogic.servlet.internal.ServletResponseImpl.send(ServletResponseImpl.java:1742)

at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1715)

at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1665)

at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)

at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)

at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)

at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)

at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)

at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:652)

at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)

at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)

Best Answer

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,655 Red Diamond
    Accepted Answer

    3) List is only an interface. The implementation behind it (ArrayList,...) is serializable if the fields in the list are serializable. List<String> is ok, List<ViewRowImpl> is not because ViewRowimpl is not serializable. Same for Map. The problem can be the 'dynamic'. If you get the data from different sources and the Ids or key are changing depending on the server, you can serialize the list, but the selection might be wrong if the key on one server points to a different resource on the other.

    4) see 3)

    5) Only class variables are serialized. All non-static variables declared in a method are not a problem as they get initialized when the method is called.


    Timo

Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,655 Red Diamond

    User, here are the short answers to your questions:

    1) no, viewScope doesn'T have an issue

    2) no, pageFlowScope won't help you resolve your issue.


    Now, after this preliminary, we should talk about the issue. You get this error because a bean in a scope higher than requestScope has properties (variables) that don't implement the serializable interface. Because of this, they can't be serialized. Now, if some process requests your bean to be serialized, e.g. because it needs to be replicated to another server, this throws the exception you see.

    The question is why you have properties or variables in the bean that can't be serialized. This points to a design problem in your application and is not an issue with the viewScope or pageFlowScope.

    The error shows that the variable is of type ViewRowImpl. Why do you have a variable of type ViewRowImpl in your bean?

    ADF is an MVC (Model View Controler) framework. ViewRow should be part of the model layer. If you use a row on the UI this layer is the binding layer. No need to store a ViewRowImpl as a bean property or variable.

    adding the Serializable interface to the viewRowImpl class won't help either. A ViewRow represents a row of a DB table in a certain stage. This information can't be copied to another server as it contains references to other memory that are not available on the other server.

    To fix the problem, remove everything from your bean that can't be serialized.


    Timo

  • User_PGA0I
    User_PGA0I Member Posts: 32 Red Ribbon

    Fantastic Timo. Thanks for the updates. Will check and test it out and let you know.

  • User_PGA0I
    User_PGA0I Member Posts: 32 Red Ribbon

    I looked at few of our Beans where we are seeing the NotSerializableException. Noticed the following:

    1) We are using ComponentReference for the fields in the Bean. This is serializable, so I assume we are good here.

    2) String, boolean, Boolean, BigDecimal variables are used as fields in the Bean. These are serializable, so I assume we are good here.

    3) We use List<SelectItem> for dynamically getting the list of select items. I see somewhere that List is not Serializable. Should we need to use ArrayList for this.

    4) We also use Map<String,String> to get values dynamically. Do we need to use HashMap instead of Map here.

    5) I see we have code in the action listeners as follows:

    DCIteratorBinding voIter = ADFUtils.findIterator("voIterName");

    voIter.getCurrentRow()

    Do we need to move this code to handle these in Model Layer.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,655 Red Diamond
    Accepted Answer

    3) List is only an interface. The implementation behind it (ArrayList,...) is serializable if the fields in the list are serializable. List<String> is ok, List<ViewRowImpl> is not because ViewRowimpl is not serializable. Same for Map. The problem can be the 'dynamic'. If you get the data from different sources and the Ids or key are changing depending on the server, you can serialize the list, but the selection might be wrong if the key on one server points to a different resource on the other.

    4) see 3)

    5) Only class variables are serialized. All non-static variables declared in a method are not a problem as they get initialized when the method is called.


    Timo