Creating JIVariant from JIArray throws NullPointerException

53 views
Skip to first unread message

Karsten Kukat

unread,
Feb 13, 2014, 7:39:00 AM2/13/14
to open...@googlegroups.com
Hello,

to write arrays via OPC i have to create a JIVariant with an JIArray as value. My first tests resulted in bad exceptions. 

Here is my own mapping:

    public static JIVariant objectArrayToJIStringArray(Object valueObject) {
        List<Object> objectArrayString = (ArrayList<Object>) valueObject;
        String[] stringArray = new String[objectArrayString.size()];
        for (int i = 0; i < objectArrayString.size(); i++) {
            stringArray[i] = objectArrayString.get(i).toString();
        }
        JIArray jiArray = new JIArray(stringArray);
        return new JIVariant(jiArray);
    }

when returning "new JIVariant(jiArray);" the exception happens. 

Exception in thread "Thread-27" java.lang.NullPointerException
at org.jinterop.dcom.core.JIMarshalUnMarshalHelper$StringImpl.getLengthInBytes(JIMarshalUnMarshalHelper.java:1287)
at org.jinterop.dcom.core.JIMarshalUnMarshalHelper.getLengthInBytes(JIMarshalUnMarshalHelper.java:352)
at org.jinterop.dcom.core.JIVariant.initArrays(JIVariant.java:1113)
at org.jinterop.dcom.core.JIVariant.<init>(JIVariant.java:1012)
at org.jinterop.dcom.core.JIVariant.<init>(JIVariant.java:1193)
at OPCTools.objectArrayToJIStringArray(OPCTools.java:376)
        ......


In the class JIMarshalUnMarshalHelper seems to be the error. 

static int getLengthInBytes(Class c,Object obj, int FLAG)
{
if(obj != null && obj.getClass().equals(JIArray.class))
{
return ((JIArray)obj).getSizeOfAllElementsInBytes();
}
else
{
if ((c != IJIComObject.class || c != IJIDispatch.class) && obj instanceof IJIComObject)
{
c = IJIComObject.class;
}

if (((SerializerDeserializer)mapOfSerializers.get(c)) == null)
{
throw new IllegalStateException(MessageFormat.format(JISystem.getLocalizedMessage(JIErrorCodes.JI_UTIL_SERDESER_NOT_FOUND),new String[]{c.toString()}));
}
return ((SerializerDeserializer)mapOfSerializers.get(c)).getLengthInBytes(obj,FLAG);
}

}

in this constellation a null value can be in the call "getLengthInBytes" which throws an exception. (return ((SerializerDeserializer)mapOfSerializers.get(c)).getLengthInBytes(obj,FLAG);)

Now i have two questions.

Is my way to write arrays wrong? (I send the values as WriteRequests like in other posts)

Is this a bug in the org.jinterop.dcom.core library? I'm using version 2.0.8

Greetings

Karsten


Reply all
Reply to author
Forward
0 new messages