-1

Please note.. the question has been cleaned up after waisting lot of EJP's time. (Sincere apologies and deeply appreciate the help extended.)

We have a client-server application. The communication is RMI. We got the following exception in the application just once. The program has been running for over 5 years now but the exception mentioned below has occured just once recently.

The exception is

    java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
    at com.company.server.TopicSessionImpl_Stub.createPublisher(Unknown Source)
    at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.calc(clientClass.java:92)
    at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.access$500(clientClass.java:37)
    at com.company.process.finance.client.transactionservers.clientClass.processTransaction(clientClass.java:346)
    at com.company.process.finance.TransactionServer.processTransaction(TransactionServer.java:50)
    at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:120)
    at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:110)
    at com.company.process.core.Manager$BrokerListener.readITMsg(Manager.java:74)
    at com.company.core.util5.FixedSizeThreadPoolMsgBus$ParallelTask.run(FixedSizeThreadPoolMsgBus.java:37)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    ... 12 more
Caused by: java.io.NotSerializableException: com.company.server.TestImplConcrete
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at com.company.server.TopicSessionImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    ... 1 more

I have gone through some post and they suggest the class TestImplConcrete should made serializable to get away with the exception. I completely aggree that the TestImplConcrete class is NOT serialized. But the question here is, if that is the only thing solving the problem how was the class woring for past 5 years and how is the class still working without any problem?

Note: we just got this issue only once and then, after restarting the process, all works fine. Also please note the question is not related to my code, it is more related to the serialization and RMI.

Code Here:

// The colling class    
Class CallingClass {
    Public void createSubscription (){

        TopicImpl topicPublisher = null;

        try {
            TopicImpl sessionInter = (TopicImpl) Naming.lookup(url);

            if (sessionInter != null) {

                topicPublisher = sessionInter.createMap();   
            }

        } catch (Exception e) {
            Logger.error(e);
        }
    }

}


The colling interface
public interface TopicImpl extends Remote {

    TestImpl createMap() throws RemoteException ;

}

// Concrete class for calling interface
public class TopicImplConcrete implements TopicImpl {

String name = "abc";

// this map is give some value during class initialization
private ConcurrentHashMap<String, TestImplConcrete> concHashMap = new ConcurrentHashMap<String, TestImplConcrete>();

    public TopicPublisher createMap() {
        TestImpl refOfHere = getMethodHere(name);
        return refOfHere;
        }

    public TestImplConcrete getMethodHere(String name) {
        if (name != null) {
            TestImplConcrete ref = concHashMap.get(name);
            if (ref != null)
                return ref;
            synchronized (this) {
                ref = concHashMap.get(name);
                if (ref != null)
                    return ref;
                ref = new TestImplConcrete(name);
                concHashMap.put(name, ref);
                try {
                    if (!ref.isExported()) {
                        UnicastRemoteObject.exportObject(ref);
                        ref.setExported(true);
                    }
                } catch (RemoteException e) {
                    log.error("Remote Exception", e);
                }
            }
            return ref;
        }
        return null;
    }
}

// The interface being sent over..
public interface TestImpl extends Remote {
    public TestImpl getMethod1()  throws RemoteException;
    public void method2()  throws RemoteException;
}

// concrete class for the interface being sent over.
public class TestImplConcrete implements TestImpl {
 private boolean isExportedBoolean;

 public boolean isExported() {
        return isExportedBoolean;
    }

    public void setExported(boolean isExportedBoolean) {
        this.isExportedBoolean = isExportedBoolean;
    }

    public TestImpl getMethod1() {
    // do something
    }

    public void method2() {
    // do something
    }
}

Please Note: the code has been edited to give only the relevent info. Please let me know if more info is required. The same code pasted above has worked fine for several years now. But this one time it showed NotSerializableException.

Nayan Sonthalia
  • 237
  • 1
  • 4
  • 22
  • "All the objects are either properly serialized or are being exported wheren ever required." The exception doesn't agree with you. `com.company.server.testImpl` is neither `Serializable` nor exported at the time `createPublisher()` is called. – user207421 Nov 26 '15 at 09:08
  • 1
    The `isPublisherExported()` test is pointless, as is the associated state and getter and setter. The object is brand new at this point. It can't possibly have been exported. Don't test things that can never be false. Better still, have the object extend `UnicastRemoteObject` so that it *is* exported on construction. – user207421 Nov 30 '15 at 12:00

1 Answers1

0

testImpl doesn't need to be Serializable, but if it isn't it does need to have been exported at the time it was passed or returned via RMI.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • thaks for the reply.. I see that the return statement does return testImpl. Is it possible that the object of testImpl is not created properly and hence an incorrect reference is returned which caused the error? – Nayan Sonthalia Nov 16 '15 at 10:01
  • Just investigate the answer I have already given, instead of indulging in wild guesses. Make sure it's exported. – user207421 Nov 16 '15 at 22:11
  • Probably i am totally confused or am beeing a dum.. I checkd and rechecked the code but all seems to be fine there. Moreover the code workes everly time but for this one ocassion. – Nayan Sonthalia Nov 18 '15 at 13:11
  • What code would that be? There's exactly none posted in your question. – user207421 Nov 26 '15 at 09:07
  • Code posted in the original post. – Nayan Sonthalia Nov 27 '15 at 10:28
  • You've posted everything *but* the code of `testImpl` and `TopicPublisherImpl` and `isPublisherExported()` etc etc. You've been futzing around with this question for two weeks. I can only assume it is very low priority. – user207421 Nov 30 '15 at 08:37
  • My bad.. copy past error.. have now updated code of TopicPublisherImpl in the mail question. TestImpl is noting but TopicPublisherImpl.. the exception is for TopicPublisherImpl..i just edited the exception trace b4 posting it here hence TestImpl. The question is not of low priority. it actually is stopping one of my process running in produciton abruptly so we have to manually restart it. Was actually serarching the web for more clues. – Nayan Sonthalia Nov 30 '15 at 09:28
  • What does '`testImpl` is nothing but `TopicPublisherImpl` mean? Where is the implementation of `TopicSessionInterface.createPublisher()`? – user207421 Nov 30 '15 at 09:49
  • just changed the name before i pasted the code to this forum... Modified the above code only to reflect testImpl so that there is no cofusion... – Nayan Sonthalia Nov 30 '15 at 09:50
  • i see how i have wasted your time here.. i appreciate your patience and do Sincere apologies.. i was jst tring to passon relevent info insted of all the info. i will not post any updated to this question any more.. i will insted close this question and post a clean question for the reference. I was just trying to give relevent info.. – Nayan Sonthalia Nov 30 '15 at 12:05