Hi,

There is two times an attribute named "LENGTH" in the schema of "Misure".

Attribute names in shapefile can only be 10 chararters long and OJ tries to 
take care that if a longer attribute must be truncated it will still get an 
unique name.
So, cut attribute name to 8 characters, check if there are duplicates, add a 
numeric ending to the body for making them unique.

What is exceptional is that Peppe has created a file that has duplicated and 
less than 10 characters long attribute names natively. OpenJUMP does not take 
this situation into account.

But I wonder how this layer is created? It is not possible to create duplicate 
attribute names from the GUI.

-Jukka Rahkonen-




Johannes Kröger wrote:

> Hey Giuseppe,

> yay, little morning programming practise for me. :)

> If I read it correctly it fails with any column name shorter than 8 
> characters, weird how this was never catched before (or I am just on the 
> wrong path).

> My line numbers are slightly off but I assume the following block is where it 
> errors for you:
 if (count<10) columnName = columnName.substring(0,8) + "_" + count;  else 
columnName = columnName.substring(0,8) + count;

> The hardcoded 8 is a problem here. A few lines above columnName is defined as:
 columnName = columnName.substring(0,Math.min(columnName.length(), 10)); Names 
will be truncated to a maximum of 10 characters here or stay as they are if 
they were <= 10 already.

> Basically what seems to happen here is this:
 // A String with less than 8 characters  String test = "1234567";  // Truncate 
to the shorter of its length or 10, here 7 so no truncation  test = 
test.substring(0,Math.min(test.length(), 10));  // Extract the substring up to 
index 8 (including)  test = test.substring(0,8);  // test's highest index is 7, 
so it's OOB

> The substring operations within the if/else need to take care of strings 
> shorter than 8 characters and truncate accordingly.

> Cheers, Hannes

> PS: SHP begone!

> PPS: It will also fail rather badly if there are more than 99 identically 
> truncated names ;)

> PPPS: Wouldn't it result in ambiguity if the truncation from 10 to 8 
> characters leads to the same string of previously different names?
abcdefghij and abcdefghik would both result in abcdefgh as "truncated + count" 
column name.

On Tue, 16 Jun 2015 07:58:53 +0000
jump-pilot-devel-requ...@lists.sourceforge.net wrote:

> Date: Tue, 16 Jun 2015 09:58:47 +0200
> From: Giuseppe Aruta <giuseppe.ar...@gmail.com>
> Subject: [JPP-Devel] Bug on saving layer to SHP
> To: OpenJump develop and use <jump-pilot-devel@lists.sourceforge.net>
> Message-ID:
>       <ca+alwnxx+4cujfs75p0sdfsvhlrdq+ddjjk90ht8y-ixu5r...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hi,
> this is the message I had when I tired to save a vector layer to
> Shapefile:
> 
> java.lang.StringIndexOutOfBoundsException: String index out of range:
> 8 at java.lang.String.substring(String.java:1907)
>     at
> com.vividsolutions.jump.io.ShapefileWriter.writeDbf(ShapefileWriter.java:435)
>     at
> com.vividsolutions.jump.io.ShapefileWriter.write(ShapefileWriter.java:295)
>     at
> com.vividsolutions.jump.io.datasource.ReaderWriterFileDataSource$1.executeUpdate(ReaderWriterFileDataSource.java:73)
>     at
> com.vividsolutions.jump.workbench.datasource.AbstractSaveDatasetAsPlugIn.run(AbstractSaveDatasetAsPlugIn.java:28)
>     at
> com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager$TaskWrapper.run(TaskMonitorManager.java:152)
>     at java.lang.Thread.run(Thread.java:744)
> 
> Saving to JML works fine
> Peppe

------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to