TypeSupport.serialize causing ArrayIndexOutOfBoundsException

3 posts / 0 new
Last post
Offline
Last seen: 4 years 3 months ago
Joined: 08/22/2016
Posts: 2
TypeSupport.serialize causing ArrayIndexOutOfBoundsException

I have an idl file that defines a char[] in a struct as follows:

struct baseDataHdr_S {
octet paramId[16];
short miscHdrBytes;
};

The autogenerated Java code looks correct, but when sending the Topic I get an error:

java.lang.ArrayIndexOutOfBoundsException: 8
at ...baseDataHdr_STypeSupport.serialize

Looking in the java code the char[] is correctly defined as a char[16], so I'm stumped why indexing char[8] during serialization would cause this exception.

rip
rip's picture
Offline
Last seen: 2 days 3 hours ago
Joined: 04/06/2012
Posts: 322

If the char that you are stuffing into the octet array are two-byte char, it will oob around 8.

Just a thought.  Are these ASCII or UTF-8 or Unicode or ... characters?

 

Offline
Last seen: 4 years 3 months ago
Joined: 08/22/2016
Posts: 2

The (rtiddsgen) created class def has a member defined like so:

public byte [] paramId=  new byte [16];

And the corresponding TypeSupport class has this block that is throwing the exception in the for loop when i1__ == 8

baseDataHdr_S typedSrc = (baseDataHdr_S) src;

for(int i1__ = 0; i1__< 16; ++i1__){

dst.writeByte(typedSrc.paramId[i1__]);
}

Given just these two sections of code, I dont see an issue. The troubling thing is that this is all happening in the autogenerated Java code. I couldn't change it if I wanted to.

Is there any kind of byte alignment going on behind the sceens?