Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RetryableErrorHandler.handleConversionError throws ArrayIndexOutOfBoundsException #509

Open
idahiron opened this issue Jul 26, 2022 · 1 comment

Comments

@idahiron
Copy link

Hello Univocity Team,

It seems that handleConversionError throws an ArrayIndexOutOfBoundsException, when a CSV file contains only one field without commas in a record while the header have seviral columns.

The row[2] fails because of that:

Input CSV:

LastName, FirstName, Number, Date
Johnson, James, 00000, 2022-7-26
Smith

Messages:

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
  at com.univocity.parsers.common.DefaultConversionProcessor.handleConversionError(DefaultConversionProcessor.java:284)
  at com.univocity.parsers.common.DefaultConversionProcessor.validateAllValues(DefaultConversionProcessor.java:173)
  at com.univocity.parsers.common.DefaultConversionProcessor.applyConversions(DefaultConversionProcessor.java:132)
  at com.univocity.parsers.common.processor.core.BeanConversionProcessor.createBean(BeanConversionProcessor.java:663)
  at com.univocity.parsers.common.processor.core.AbstractBeanProcessor.rowProcessed(AbstractBeanProcessor.java:54)
  at com.univocity.parsers.common.Internal.process(Internal.java:30)
  ... 62 common frames omitted

ExceptionHandlerExceptionResolver - Resolved [com.univocity.parsers.common.DataProcessingException: 
Unexpected error processing input row [Smith] using Processor com.univocity.parsers.common.processor.BeanListProcessor.
<EOL>Internal state when error was thrown: row=[Smith]] (AbstractHandlerExceptionResolver.java:208)

Original source: my app encounters an error when it processes row[column] = defaultValue;

protected final boolean handleConversionError(Throwable ex, Object[] row, int column) {
		if (row != null && row.length < column) {
			//expand row so column index won't make error handlers blow up.
			row = Arrays.copyOf(row, column + 1);
		}
		DataProcessingException error = toDataProcessingException(ex, row,  #column);

		if (column > -1 && errorHandler instanceof RetryableErrorHandler) {
			((RetryableErrorHandler) errorHandler).prepareToRun();
		}

		error.markAsHandled(errorHandler);
		errorHandler.handleError(error, row, context);

		if (column > -1 && errorHandler instanceof RetryableErrorHandler) {
			RetryableErrorHandler retry = ((RetryableErrorHandler) errorHandler);
			Object defaultValue = retry.getDefaultValue();
			row[column] = defaultValue;
			return !retry.isRecordSkipped();
		}
		return false;
	}

univocity-parsers, version: 2.9.1

Thank you for your work on the excellent Univocity library.

@lavanya051992
Copy link

I am having the same issue, if there are less characters in a file, the exception is thrown. Did you find any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants