[udig-devel] DbaseFileWriter problems on ugly strings

Andrea Antonello andrea.antonello at gmail.com
Wed Jan 16 05:24:35 PST 2008


I have a problem when trying to merge various layers to a shapefile.

An exception is thrown from the DbaseFileWriter that is due to the fact
that the content of the string was written with international
characters and on my pc they don't seem to be encoded properly.
Nevertheless, since I do not care about the content, I would not expect
an error.

The content is:

------------------------------------------------------------------

schräge
Länge der
Brücke 15 m, starke
Verängung der Abflusssekti

------------------------------------------------------------------

for which bash's wc counts 317 bytes.


In the method getFieldString of the DbaseFileWriter the following
happens:

int currentBytes=s.substring(0, Math.min(size,
s.length())).getBytes().length; 

where s.length() = 188
size, which is maxsize = 254
and currentBytes gets = 316

so the following check gives true, which is ok, since international
chars are taken into account:

if( currentBytes>size ){
            char[] c=new char[1];
            for( int index=size-1; currentBytes>size; index--){

the following line throws an arrayoutofbounds, since the count of the
buffer is 188 and we are accessing position 253. 

		c[0] = buffer.charAt(index);

I don't understand exactly the problem, since the buffer is initialized
with dimension 255 and it should not throw the exception.


Any idea on what the problem is?


Andrea


More information about the udig-devel mailing list