How to send null parameter in Java-IDL?

B

billdavidcn

1.I need to transfer a complex type with an array variable member in a
Java-IDL based program. But if the array is empty, the program will
report a java.lang.NullPointerException.
Is there any solution to it except block the request in client side?

The following is my idl:

#ifndef __SAMPLE_IDL__
#define __SAMPLE_IDL__

typedef sequence <octet> ByteArray;

struct ComplexType {
ByteArray data;
string info;
};

interface Sample {
void doSomething(in ComplexType value);
};

#endif // __SAMPLE_IDL__

And the following is a snippet from the client program:

ComplexType value = new ComplexType();
// leave data field to be NULL
value.info = "Hello, World!";
xxx.doSomething(value);

If I provide an empty data field for ComplexType, it will fail to
serialize the parameter value.
And the following is part of the autogenerated class ByteArrayHelper:

public static void write (org.omg.CORBA.portable.OutputStream
ostream, byte[] value)
{
ostream.write_long (value.length);
ostream.write_octet_array (value, 0, value.length);
}

It always throws java.lang.NullPointerException at the line:
ostream.write_long (value.length);

2.If I have another method:
void echoString(in string info);

If the client call this method with a null parameter, ORB will
complain too. But sometimes, it's reasonable requirement. Is it any
solution to this? Redefine a method:
void echoString();
or block such kind of request by client?

There must be a better solution. But what is it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top