This discussion is archived
5 Replies Latest reply: Jul 30, 2013 12:10 AM by Biswaa RSS

<BEA-000126> java.rmi.MarshalException: failed to marshal

thenrick Newbie
Currently Being Moderated
We are getting the following error in our clustered QA environment. We run Weblogic 10.3.3.0 on linux.

####<Mar 29, 2011 3:59:54 PM CDT> <Error> <Cluster> <app2.qa.server.com> <qa_app2j> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1301432394933> <BEA-000126> <All session objects should be serializable to replicate. Check the objects in your session. Failed to replicate non-serializable object.
java.rmi.MarshalException: failed to marshal update(Lweblogic.cluster.replication.ROID;ILjava.io.Serializable;Ljava.lang.Object;); nested exception is:
java.io.NotSerializableException: com.tjf.admin.virtualFair.Job$1
at weblogic.rjvm.BasicOutboundRequest.marshalArgs(BasicOutboundRequest.java:92)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:221)
at weblogic.cluster.replication.ReplicationManager_1033_WLStub.update(Unknown Source)
at sun.reflect.GeneratedMethodAccessor15419.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at weblogic.cluster.replication.SecureReplicationInvocationHandler$ReplicationServicesInvocationAction.run(SecureReplicationInvocationHandler.java:184)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.cluster.replication.SecureReplicationInvocationHandler.invoke(SecureReplicationInvocationHandler.java:154)
at $Proxy98.update(Unknown Source)
at weblogic.cluster.replication.ReplicationManager.updateSecondary(ReplicationManager.java:535)
at weblogic.servlet.internal.session.ReplicatedSessionData.syncSession(ReplicatedSessionData.java:594)
at weblogic.servlet.internal.session.ReplicatedSessionContext.sync(ReplicatedSessionContext.java:85)
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.syncSession(ServletRequestImpl.java:2810)
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.syncSession(ServletRequestImpl.java:2785)
at weblogic.servlet.internal.ServletResponseImpl$1.run(ServletResponseImpl.java:1480)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.ServletResponseImpl.send(ServletResponseImpl.java:1474)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1455)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

Here is the java file that is causing this:


package com.tjf.admin.virtualFair;

import com.tjf.TargetedJobFairsConstants;
import com.tjf.util.TargetedJobFairsToolBox;
import org.apache.log4j.Logger;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Comparator;
import java.util.TreeMap;

public class Job implements Serializable {
     protected int id;
     protected String name;
     protected String description;
     protected int companyId;
     protected String hash;

     private static Logger logger = initializeLogger();

     protected static Logger initializeLogger() {
          Logger logger = Logger.getLogger(TargetedJobFairsConstants.TJF_LOG4J_NAME);
          logger.info("logger initialized!");
          return logger;
     }


     public Job(String name, String description, int companyId) {
          this.name = name;
          this.description = description;
          this.companyId = companyId;
     }

     public Job(int id, String name, String description, int companyId) {
          this.id = id;
          this.name = name;
          this.description = description;
          this.companyId = companyId;
     }

     public Job(String name, String description) {
          this.name = name;
          this.description = description;
          this.companyId = companyId;
     }

     public String getHash() {
          if (id != -1 && name != null && !name.equals("")) {
               return TargetedJobFairsToolBox.createHash(name, "" + id);
          } else {
               return null;
          }
     }

     public int getCompanyId() {
          return companyId;
     }

     public void setCompanyId(int companyId) {
          this.companyId = companyId;
     }

     public int getId() {
          return id;
     }

     public void setId(int id) {
          this.id = id;
     }

     public String getName() {
          return name;
     }

     public void setName(String name) {
          this.name = name;
     }

     public String getDescription() {
          return description;
     }

     public void setDescription(String description) {
          this.description = description;
     }

     public static boolean validateName(String name, StringBuffer message) {
          if (name != null && !name.trim().equals("")) {
               // check for duplicated Virtual Fair Company Name
               return true;
          } else {
               if (message.length() > 0) {
                    message.append(", Name ");
               } else {
                    message.append(" Name ");
               }
               return false;
          }
     }

     public static boolean validateDescription(String description, StringBuffer message) {
          if (description != null && !description.trim().equals("")) {
               return true;
          } else {
               if (message.length() > 0) {
                    message.append(", Description ");
               } else {
                    message.append(" Description ");
               }
               return false;
          }
     }

     public static boolean validateCompanyIDString(String companyID, StringBuffer message) {
          if (companyID != null && !companyID.trim().equals("")) {
               return true;
          } else {
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(32) ");
               } else {
                    message.append(" unknown virtual fair error(32) ");
               }
               return false;
          }
     }

     protected boolean insertJob(Connection tjfConn, StringBuffer message) {
          PreparedStatement insertJobStmt = null;
          String insertJobSQL = null;

          try {
               insertJobSQL = "insert into VIRTUAL_FAIR_JOB ( NAME, DESCRIPTION, COMPANY_ID ) " +
                         "values (?, ?, ?) ";

               insertJobStmt = tjfConn.prepareStatement(insertJobSQL);
               insertJobStmt.setString(1, this.name);
               insertJobStmt.setString(2, this.description);
               insertJobStmt.setInt(3, this.companyId);

               insertJobStmt.executeUpdate();
               message.append(" Job \"" + this.name + "\" was successfully created.");
               return true;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(33) ");
               } else {
                    message.append(" unknown virtual fair error(33) ");
               }
               return false;
          }
     }

     protected boolean updateJob(Connection tjfConn, StringBuffer message) {
          PreparedStatement insertJobStmt = null;
          String insertJobSQL = null;

          try {
               insertJobSQL = "update VIRTUAL_FAIR_JOB set NAME = ?, DESCRIPTION = ? where" +
                         " COMPANY_ID = ? and ID = ?";

               insertJobStmt = tjfConn.prepareStatement(insertJobSQL);
               insertJobStmt.setString(1, this.name);
               insertJobStmt.setString(2, this.description);
               insertJobStmt.setInt(3, this.companyId);
               insertJobStmt.setInt(4, this.id);

               insertJobStmt.executeUpdate();
               message.append(" Job \"" + this.name + "\" was successfully updated.");
               return true;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(34) ");
               } else {
                    message.append(" unknown virtual fair error(34) ");
               }
               return false;
          }
     }

     public static boolean deleteJobByCompanyID(Connection tjfConn, int companyID, StringBuffer message) {
          PreparedStatement deleteJobStmt = null;
          String deleteJobSQL = null;

          try {
               deleteJobSQL = "delete from VIRTUAL_FAIR_JOB where " +
                         " COMPANY_ID = ? ";

               deleteJobStmt = tjfConn.prepareStatement(deleteJobSQL);
               deleteJobStmt.setInt(1, companyID);

               deleteJobStmt.executeUpdate();
               message.append(" Jobs were successfully deleted.");
               return true;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(35) ");
               } else {
                    message.append(" unknown virtual fair error(35) ");
               }
               return false;
          }
     }

     public static boolean deleteJob(Connection tjfConn, int jobID, int companyID, StringBuffer message) {
          PreparedStatement deleteJobStmt = null;
          String deleteJobSQL = null;

          try {
               deleteJobSQL = "delete from VIRTUAL_FAIR_JOB where " +
                         " COMPANY_ID = ? and ID = ? ";

               deleteJobStmt = tjfConn.prepareStatement(deleteJobSQL);
               deleteJobStmt.setInt(1, companyID);
               deleteJobStmt.setInt(2, jobID);

               deleteJobStmt.executeUpdate();
               message.append(" Job was successfully deleted.");
               return true;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(36) ");
               } else {
                    message.append(" unknown virtual fair error(36) ");
               }
               return false;
          }
     }

     public static TreeMap<Job, Integer> getJobListforCompany(Connection tjfConn, int companyID, StringBuffer message) {
          TreeMap<Job, Integer> jobsList = new TreeMap<Job, Integer>(new Comparator() {
               public int compare(Object job, Object anotherJob) {
                    String name1 = ((Job) job).getName();
                    String name2 = ((Job) anotherJob).getName();
                    return name1.toLowerCase().compareTo(name2.toLowerCase());
               }
          });
          PreparedStatement getJobListStmt = null;
          String getJobListSQL = null;
          ResultSet getJobListRset = null;
          try {
               getJobListSQL = "select ID, NAME, DESCRIPTION, COMPANY_ID from VIRTUAL_FAIR_JOB where COMPANY_ID = ?";
               getJobListStmt = tjfConn.prepareStatement(getJobListSQL);
               getJobListStmt.setInt(1, companyID);
               getJobListRset = getJobListStmt.executeQuery();

               while (getJobListRset.next()) {
                    Job holdJob = new Job(getJobListRset.getInt(1),
                              getJobListRset.getString(2),
                              getJobListRset.getString(3),
                              getJobListRset.getInt(4));
                    jobsList.put(holdJob, holdJob.id);
               }
               return jobsList;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(37) ");
               } else {
                    message.append(" unknown virtual fair error(37) ");
               }
               return null;
          }
     }

     public static Job getJobByID(Connection tjfConn, int jobID, StringBuffer message) {

          PreparedStatement getJobListStmt = null;
          String getJobListSQL = null;
          ResultSet getJobListRset = null;
          try {
               getJobListSQL = "select ID, NAME, DESCRIPTION, COMPANY_ID from VIRTUAL_FAIR_JOB where ID = ?";
               getJobListStmt = tjfConn.prepareStatement(getJobListSQL);
               getJobListStmt.setInt(1, jobID);
               getJobListRset = getJobListStmt.executeQuery();

               Job holdJob = null;
               if (getJobListRset.next()) {
                    holdJob = new Job(getJobListRset.getInt(1),
                              getJobListRset.getString(2),
                              getJobListRset.getString(3),
                              getJobListRset.getInt(4));
               }
               return holdJob;
          } catch (Exception x) {
               logger.error(x, x);
               if (message.length() > 0) {
                    message.append(", unknown virtual fair error(38) ");
               } else {
                    message.append(" unknown virtual fair error(38) ");
               }
               return null;
          }
     }
}

Any suggestions on what might cause this?

Thanks,
Tom
  • 1. Re: <BEA-000126> java.rmi.MarshalException: failed to marshal
    794514 Pro
    Currently Being Moderated
    Hi Tom,

    <h2>Suspect-1:</h2>
    Your class contains one NonSerializable variable declared at the Instance Variable level " org.apache.log4j.Logger" at the following line:
    private static Logger logger = initializeLogger();
    Even if your class Job implements Serializable ....still the Instance variables declared inside this class must be either of the following:
    *1).* Primitive Datatypes
    or
    *2).* The Instance Variables also must be Serializable
    or
    *3).* The Non-Serializable Instance variables must be declared as "transient"
    Example:
    private transient Logger logger = initializeLogger();
    <BR>
    <font color=maroon>NOTE: Static variables won't get saved by serialization unless you add special code to do so. In our context, statics are usually a bad idea anyway.
    </font>
    <BR><BR>


    <h2>Suspect-2:</h2>
    Still if you face any issue in finding the Non-Serialble Objects which arecausing the failure then use the JSP file (*SerializationTest.jsp*) mentioned in the following link:

    Topic:  Session Replication Issues
    http://middlewaremagic.com/weblogic/?p=290


    <h2><font color=red>Suspect-3:</font></h2>
    java.io.NotSerializableException: com.tjf.admin.virtualFair.Job$1

    In the above cause of the exception you will notice that the class which is not actually serializable is *"Job$1"* According to the J2SE specification the Inner classes are represented using the special symbol '$'
    Example: A.java
    class A
       {
              class B
                {
                 }
       }
    If you will compile the above program then you will find that there are two classes generated A.class and A$B.class.
    But if your inner class is an Anonymous inner class then in that case the generated class name would be something like "A$1" like "Job$1"

    In your code i DON'T see any  kind of inner class/ Anonymous inner class is declared......it means WebLogic is doing something wrong while making this object as a Proxy object the injected code is causing the NonSerializablke Exceptiomn

    <BR><BR>
    Thanks
    Ravish Mody
  • 2. Re: <BEA-000126> java.rmi.MarshalException: failed to marshal
    thenrick Newbie
    Currently Being Moderated
    I looked it over again and there is an Anonymous inner class:

    public static TreeMap<Job, Integer> getJobListforCompany(Connection tjfConn, int companyID, StringBuffer message) {
    TreeMap<Job, Integer> jobsList = new TreeMap<Job, Integer>(new Comparator() {
    public int compare(Object job, Object anotherJob) {
    String name1 = ((Job) job).getName();
    String name2 = ((Job) anotherJob).getName();
    return name1.toLowerCase().compareTo(name2.toLowerCase());
    }
    });

    This will have to be changed.

    Thanks Ravish!

    Tom
  • 3. Re: <BEA-000126> java.rmi.MarshalException: failed to marshal
    thenrick Newbie
    Currently Being Moderated
    I created the following class :

    public class JobComparator implements Comparator {
    public int compare(Object job, Object anotherJob) {
    String name1 = ((Job) job).getName();
    String name2 = ((Job) anotherJob).getName();
    return name1.toLowerCase().compareTo(name2.toLowerCase());
    }
    }

    And changed the code to call it to

    TreeMap<Job, Integer> jobsList = new TreeMap<Job, Integer>(new JobComparator());

    And it seems to work well.

    Thanks again Ravish!!
    Tom [Java Comparator Example|http://www.javadeveloper.co.in/java-example/java-comparator-example.html]

    Edited by: thenrick on Apr 7, 2011 3:33 PM
  • 4. Re: <BEA-000126> java.rmi.MarshalException: failed to marshal
    794514 Pro
    Currently Being Moderated
    W O N D E R F U L

    Regards,

    Ravish Mody
    http://middlewaremagic.com/weblogic
    Come, Join Us and Experience The Magic…
  • 5. Re: <BEA-000126> java.rmi.MarshalException: failed to marshal
    Biswaa Newbie
    Currently Being Moderated

    Hi Thenrik,

    This is right but Serialization does not concern about methods. and it is only about Instance variables.

     

    public static TreeMap<Job, Integer> getJobListforCompany(Connection tjfConn, int companyID, StringBuffer message) {

               TreeMap<Job, Integer> jobsList = new TreeMap<Job, Integer>(new Comparator() {

                    public int compare(Object job, Object anotherJob) {

                         String name1 = ((Job) job).getName();

                         String name2 = ((Job) anotherJob).getName();

                         return name1.toLowerCase().compareTo(name2.toLowerCase());

                    }

               });

               PreparedStatement getJobListStmt = null;

               String getJobListSQL = null;

               ResultSet getJobListRset = null;

               try {

                    getJobListSQL = "select ID, NAME, DESCRIPTION, COMPANY_ID from VIRTUAL_FAIR_JOB where COMPANY_ID = ?";

                    getJobListStmt = tjfConn.prepareStatement(getJobListSQL);

                    getJobListStmt.setInt(1, companyID);

                    getJobListRset = getJobListStmt.executeQuery();

     

                    while (getJobListRset.next()) {

                         Job holdJob = new Job(getJobListRset.getInt(1),

                                   getJobListRset.getString(2),

                                   getJobListRset.getString(3),

                                   getJobListRset.getInt(4));

                         jobsList.put(holdJob, holdJob.id);

                    }

                    return jobsList;

               } catch (Exception x) {

                    logger.error(x, x);

                    if (message.length() > 0) {

                         message.append(", unknown virtual fair error(37) ");

                    } else {

                         message.append(" unknown virtual fair error(37) ");

                    }

                    return null;

               }

     

    So please tell how that inner class will effect the serialization process of the instance of this calss?

    thanks in advance.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points