异常org.omg.CORBA.BAD

    xiaoxiao2023-10-06  176

    小声bb:这个是在我写一个corba博客的时候偶然发现的,百度后发现不少人遇到这个错误而且还有些没有被解决,由于我没有实际遇到这个问题,所以此处只是对这个错误及解决方法的一些分析猜想,希望能对你有所帮助。如果有错请不要骂我quq


    这个错误是在idl文件下生成的包中的一个文件的函数内被抛出。

    我的idl文件是这样的

    module sample{ interface HelloWorld{ wstring sayHello(); }; };

    在它生成的sample包中有一个HelloWorldHelper.java文件(文件的所有代码请见最后),里面有一个narrow(),具体内容如下:

    public static sample.HelloWorld narrow (org.omg.CORBA.Object obj) { if (obj == null) return null; else if (obj instanceof sample.HelloWorld) return (sample.HelloWorld)obj; else if (!obj._is_a (id ())) throw new org.omg.CORBA.BAD_PARAM (); else { org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); sample._HelloWorldStub stub = new sample._HelloWorldStub (); stub._set_delegate(delegate); return stub; } }

    在第二个else if中,判断如果(!obj._is_a (id ()))则抛出这个org.omg.CORBA.BAD_PARAM ()异常,而id()这个函数也是在HelloWorldHelper.java中被定义的

    id()的内容是

    public static String id () { return _id; }

    而_id是在HelloWorldHelper.java中一开始被定义的

    private static String _id = "IDL:sample/HelloWorld:1.0";//IDL:接口数字语言

    所以这个异常的错误原因可能是生成id失败或者为空。

    同时我在stackflow上看到有人也遇到了这个问题,https://stackoverflow.com/questions/28851733/apache-camel-update-route-through-jmx-throws-org-omg-corba-bad-param,他是在博客的服务器端更新时遇到的这个问题,回答的那个人说他是在本地跑的就没有报这个错(不失为一种解决办法?/发抖),他说在本地跑Camel就会抛出一个异常,但是不能再客户端加载。异常为

    Caused by: java.lang.ClassNotFoundException: org.apache.camel.FailedToCreateRouteException (no security manager: RMI class loader disabled)

    以下是HelloWorldHelper.java的源代码

    package sample; /** * sample/HelloWorldHelper.java . * 由IDL-to-Java 编译器 (可移植), 版本 "3.2"生成 * 从HelloWorld.idl * 2019年5月25日 星期六 上午10时02分35秒 CST */ abstract public class HelloWorldHelper { private static String _id = "IDL:sample/HelloWorld:1.0"; public static void insert (org.omg.CORBA.Any a, sample.HelloWorld that) { org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); a.type (type ()); write (out, that); a.read_value (out.create_input_stream (), type ()); } public static sample.HelloWorld extract (org.omg.CORBA.Any a) { return read (a.create_input_stream ()); } private static org.omg.CORBA.TypeCode __typeCode = null; synchronized public static org.omg.CORBA.TypeCode type () { if (__typeCode == null) { __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (sample.HelloWorldHelper.id (), "HelloWorld"); } return __typeCode; } public static String id () { return _id; } public static sample.HelloWorld read (org.omg.CORBA.portable.InputStream istream) { return narrow (istream.read_Object (_HelloWorldStub.class)); } public static void write (org.omg.CORBA.portable.OutputStream ostream, sample.HelloWorld value) { ostream.write_Object ((org.omg.CORBA.Object) value); } public static sample.HelloWorld narrow (org.omg.CORBA.Object obj) { if (obj == null) return null; else if (obj instanceof sample.HelloWorld) return (sample.HelloWorld)obj; else if (!obj._is_a (id ())) throw new org.omg.CORBA.BAD_PARAM (); else { org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); sample._HelloWorldStub stub = new sample._HelloWorldStub (); stub._set_delegate(delegate); return stub; } } public static sample.HelloWorld unchecked_narrow (org.omg.CORBA.Object obj) { if (obj == null) return null; else if (obj instanceof sample.HelloWorld) return (sample.HelloWorld)obj; else { org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); sample._HelloWorldStub stub = new sample._HelloWorldStub (); stub._set_delegate(delegate); return stub; } } }

     

    最新回复(0)