Archived

This forum has been archived. Please start a new discussion on GitHub.

package metadata directive - ClassCast Exception

Hi,

I am getting ClassCast Exception when I use the package metadata directive.

I am using Ice 1.5.1 distribution running on Win2K pro, JDK 1.4.2.

Here's my Slice definition:
Printer.ice
"java:package:com.testing"

module print {
class Data {
string name;
int number;
};

interface Printer {
void printString(Data s);
};
};


PrinterI.java
package com.testing.print;

import Ice.Current;

/**
* The <code>PrinterI </code>
*
* @author Venkat Ramana Sonnathi (HTC Global Svc. Inc.)
* @version 1.0
*/
public class PrinterI extends _PrinterDisp{
public void printString(Data s, Current __current) {
System.out.println("s = " + s.name);
}
}

Server.java
public class Server {
public static void
main(String[] args) {
int status = 0;
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectAdapter adapter
= ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");
Ice.Object object = new PrinterI();
adapter.add(object,
Ice.Util.stringToIdentity("SimplePrinter"));
adapter.activate();
ic.waitForShutdown();
} catch (Ice.LocalException e) {
e.printStackTrace();
status = 1;
} catch (Exception e) {
System.err.println(e.getMessage());
status = 1;
} finally {
if (ic != null)
ic.destroy();
}
System.exit(status);
}
}

Client.java
public class Client {
public static void
main(String[] args) {
int status = 0;
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000");
PrinterPrx printer
= PrinterPrxHelper.checkedCast(base);
if (printer == null)
throw new Error("Invalid proxy");
Data data = new Data();
data.name = "Testing";
printer.printString(data);
} catch (Ice.LocalException e) {
e.printStackTrace();
status = 1;
} catch (Exception e) {
System.err.println(e.getMessage());
status = 1;
} finally {
if (ic != null)
ic.destroy();
}
System.exit(status);
}
}

When run the client, I get the following error:

Ice.UnknownLocalException
unknown = "Ice.NoObjectFactoryException
type = "::print::Data"
at IceInternal.BasicStream.patchReferences(BasicStream.java:1604)
at IceInternal.BasicStream.readObject(BasicStream.java:1365)
at IceInternal.BasicStream.readPendingObjects(BasicStream.java:1487)
at com.testing.print._PrinterDisp.___printString(_PrinterDisp.java:59)
at com.testing.print._PrinterDisp.__dispatch(_PrinterDisp.java:102)
at IceInternal.Incoming.invoke(Incoming.java:152)
at IceInternal.Connection.message(Connection.java:1173)
at IceInternal.ThreadPool.run(ThreadPool.java:689)
at IceInternal.ThreadPool.access$100(ThreadPool.java:12)
at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:1103)
Caused by: java.lang.ClassCastException
at com.testing.print.DataHolder$Patcher.patch(DataHolder.java:32)
at IceInternal.BasicStream.patchReferences(BasicStream.java:1600)
... 9 more
"
at IceInternal.Outgoing.invoke(Outgoing.java:158)
at com.testing.print._PrinterDelM.printString(_PrinterDelM.java:26)
at com.testing.print.PrinterPrxHelper.printString(PrinterPrxHelper.java:32)
at com.testing.print.PrinterPrxHelper.printString(PrinterPrxHelper.java:19)
at Client.main(Client.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

Looks like the package metadata is not added to the object identities.

Thanks,
--Venkat.

Comments

  • mes
    mes California
    Hi Venkat,

    This is a known problem that will be fixed in the next release. As a workaround, you can define and install object factories for classes. Unfortunately, this workaround isn't possible for user exceptions.

    Take care,
    - Mark
  • Having the same problem

    I am having the same problem. I have an ice client in Java and an ice server in C#. But the problem, it seems, is not in the metadata. I have deleted the metadata. And still the result is the ClassCastException. The function checkedCast is failing, then in the catch clause it is trying to copy the base into the new PrxHelper and it is throwing another exception about "can not evaluate toString() method".

    Any thoughts what to do?

    my client code:
    public static void main(String[] args)
        {
          try
          {
            IStudyWorkListPrx study_list = null;
            Ice.Communicator ic = Ice.Util.initialize();
    
            Ice.ObjectPrx base = ic.stringToProxy("StudyWorkListService:default -p 10000");
            study_list = IStudyWorkListPrxHelper.checkedCast(base);
    
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
    

    My server code is:
    module PACSServicesContractIce
    {
    
    interface IStudyWorkList
    {
       ........
        TabularQueryResult getStudyItems(StudyListQuery query, QueryOptions options); 
    
      //add get studies method
    };
    
    };
    
  • mes
    mes California
    Welcome to the forum!

    I'm afraid we'll need more information from you in order to narrow down the problem:
    • What version of Ice are you using?
    • What JDK are you using?
    • What operating system(s) are you using?
    • Can you provide the complete stack trace of the exception?
    • Did you completely remove all of the generated code after making your metadata changes and recompile your Slice files?
    Thanks,
    Mark