当前位置: 代码迷 >> J2SE >> 怎么在Java IDL中传递null参数
  详细解决方案

怎么在Java IDL中传递null参数

热度:37   发布时间:2016-04-24 14:40:46.0
如何在Java IDL中传递null参数?
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?

------解决方案--------------------
好像不可以,你只能传空对象。
------解决方案--------------------
你试一下IDL类型定义为any,调试一下java和c++分别怎么处理
  相关解决方案