unlockha / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
1 stars 0 forks source link

StringIndexOutOfBoundsException on Unmarshalling a repeating segment of indeterminate length #90

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?  
--------------------------------------

(maven project attached with failed JUnit Test case)
1 run maven test 

What is the expected output? What do you see instead?
-----------------------------------------------------

Expected: an object with unmarshalled content on it
See instead: StringIndexOutOfBoundsException during unmarshalling

What version of BeanIO are you using? What JDK version?
-------------------------------------------------------

JDK 1.6 
BeanIO 2.04 / 2.05 / 2.06 / 2.1.0.M.1

Please provide any additional information below.

This error does not occur in version 2.03 or earlier.

It was introduced as part of the modifications in 2.0.4 for supporting segments 
of indeterminate length in the middle of the stream.

The cause of the error is that the calculated max possible position of a field 
is larger than the length of the stream, so it gets the 
StringIndexOutOfBoundsException when tries to do a substring (see the 
stacktrace below)

Stack Trace of the error during the Junit Test:
java.lang.StringIndexOutOfBoundsException: String index out of range: 27
    at java.lang.String.substring(String.java:1934)
    at org.beanio.internal.parser.format.fixedlength.FixedLengthUnmarshallingContext.getFieldText(FixedLengthUnmarshallingContext.java:85)
    at org.beanio.internal.parser.format.fixedlength.FixedLengthFieldFormat.extractFieldText(FixedLengthFieldFormat.java:70)
    at org.beanio.internal.parser.format.fixedlength.FixedLengthFieldFormat.extract(FixedLengthFieldFormat.java:39)
    at org.beanio.internal.parser.Field.unmarshal(Field.java:207)
    at org.beanio.internal.parser.Segment.unmarshal(Segment.java:100)
    at org.beanio.internal.parser.CollectionParser.unmarshal(CollectionParser.java:148)
    at org.beanio.internal.parser.Segment.unmarshal(Segment.java:100)
    at org.beanio.internal.parser.Segment.unmarshal(Segment.java:100)
    at org.beanio.internal.parser.Record.unmarshal(Record.java:80)
    at org.beanio.internal.parser.BeanReaderImpl.internalRead(BeanReaderImpl.java:104)
    at org.beanio.internal.parser.BeanReaderImpl.read(BeanReaderImpl.java:66)
    at org.beanio.test.AppTest.testApp(AppTest.java:81)

Original issue reported on code.google.com by EloyA...@gmail.com on 17 Jul 2013 at 4:17

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks.  I'll try to look into it this weekend.

-Kevin

Original comment by kevin.s...@gmail.com on 19 Jul 2013 at 2:38

GoogleCodeExporter commented 8 years ago
Fixed for release 2.0.7.  Snapshot JAR attached.

Let me know if you have any further issues with this build.

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 24 Jul 2013 at 2:55

Attachments:

GoogleCodeExporter commented 8 years ago
Kevin, 

The new fix works perfect, and pass all our test.  
Thanks! You are doing a great job with this project.

Eloy.

Original comment by EloyA...@gmail.com on 24 Jul 2013 at 5:19

GoogleCodeExporter commented 8 years ago

Original comment by kevin.s...@gmail.com on 7 Sep 2013 at 6:19