Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Canabral
Contributor

Split / ArrayIndexOutOfBoundsException

Hello,

I have a csv file:

COL1|COL2|COL3

avant|99999;88888;77777|après

I want to split column 2.

So I did in a JavaRow:

output_row.COL1 = input_row.COL1;

output_row.COL2_1 = StringHandling.TRIM(input_row.COL2).split(";")[0];

output_row.COL2_2 = StringHandling.TRIM(input_row.COL2).split(";")[1];

output_row.COL2_3 = StringHandling.TRIM(input_row.COL2).split(";")[2];

output_row.COL3 = input_row.COL3;

But I have this error: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

it's ok only with

output_row.COL2_1 = StringHandling.TRIM(input_row.COL2).split(";")[0];

I don't understand because I have 3 elements and if I test with

StringHandling.TRIM(input_row.COL2).split(";").length,

it turns out 3 for me...

Thanks for your help.

Labels (2)
3 Replies
Anonymous
Not applicable

Hello @Simon Thieffry​ ,

I can't reproduce the issue in my side, could you please provide the whole job execution error log for more investigation? thanks

 

Best regards

Aiming

Canabral
Contributor
Author

Hello,

 

here is the error log:

 

Démarrage du Job test à 10:31 04/05/2023.

[statistics] connecting to socket on port 3699

[statistics] connected

Exception in component tJavaRow_1 (test)

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

at godin.test_0_1.test.tFileInputDelimited_1Process(test.java:1059)

at godin.test_0_1.test.runJobInTOS(test.java:1513)

at godin.test_0_1.test.main(test.java:1351)

[statistics] disconnected

 

Job test terminé à 10:31 04/05/2023. [Code de sortie = 1]

 

And more info on the job in the capture.

 

Thanks.

 

Simon

 

Canabral
Contributor
Author

Hello,

 

No, there is no space in my separator, that is semicolon.

 

But using the code with the intermediate variable it works :

 

String[] col2Values = StringHandling.TRIM(input_row.COL2).split("; ");

output_row.COL2_1 = col2Values.length >= 1 ? col2Values[0] : "";

output_row.COL2_2 = col2Values.length >= 2 ? col2Values[1] : "";

output_row.COL2_3 = col2Values.length >= 3 ? col2Values[2] : "";

 

Thanks.

 

Simon