fyzhou / beanio

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

Not computing record lengths properly for nested beans #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?  If applicable, please provide a
mapping configuration and sample record input to recreate the problem.
1.Run attached sample with mapping.xml. It will work fine.
2.Run with mapping-bad.xml, it will not parse, throwing a 'field gaps not 
allowed' error. 
3.Datafile.txt also attached.

What is the expected output? What do you see instead?
Expected mapping file to parse, get: "Invalid <beanNameHere> bean 
configuration: field gaps not allowed for children of collections");

What version of BeanIO are you using? What JDK version?
1.2.4, JDSK 1.5

Please provide any additional information below.
The issue only occurs when a field is declared after a bean which is already a 
child of a bean. I.e.: this works fine:
<record ...>
  <bean name="outer">
   <field name="atOuterBeanLevelBefore" />
   <bean name="inner">
      <field .../>
    </bean>
  </bean>
</record>

this does NOT work:
<record ...>
  <bean name="outer">
    <bean name="inner">
      <field .../>
    </bean>
    <field name="atOuterBeanLevelAfter" />
  </bean>
</record>

Original issue reported on code.google.com by cbanner...@gmail.com on 25 Apr 2012 at 9:17

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I was able to reproduce the issue and am working on a solution.

Original comment by kevin.s...@gmail.com on 26 Apr 2012 at 3:41

GoogleCodeExporter commented 9 years ago
Thanks for the quick issue acceptance.
I was wondering if the fix would make it back to v1.2.x and what you think 
would be a timeline for a fix/build (as usual, we are a little under the gun on 
a project). 

Please let us know if we can assist in any way; if you could point us in the 
right direction within the code, we can attempt a fix....

Thanks,
Chet

Original comment by cbanner...@gmail.com on 26 Apr 2012 at 2:39

GoogleCodeExporter commented 9 years ago
Hi Chet,

A fix will definitely be applied to the next 1.2.x release.  (I didn't try it, 
but I doubt the issue exists in 2.x.)  I hope to have a patch in the next few 
days.

The issue is in class FlatStreamDefinitionFactory, although bewarned there is 
some code I'm not particularly proud of in there :)  I tried simply commenting 
out the call to the method that performs the validation, but it looks like its 
still computing the record length incorrectly so that won't get you too far...  
I don't think the fix will be too difficult- I just need to find the time to do 
it right...

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 26 Apr 2012 at 6:42

GoogleCodeExporter commented 9 years ago
Hi Kevin,
I was focussing my attention on FlatStreamDefinitionFactory as well...
Ironically, I had commented out the call to validateCollections, but as you 
point out, the total length is being computed incorrectly. :) 
I wonder if the same 'logocal' fix needs to be applied to two methods in this 
class?

Thanks in advance, and awesome job on bean IO overall!

Original comment by cbanner...@gmail.com on 26 Apr 2012 at 6:51

GoogleCodeExporter commented 9 years ago
Kevin,
Just noticed something interesting. It appears this error is thrown when there 
are fields in more than one spot inside a bean which is already a child. For 
example, this works:
  <stream name="records" format="fixedlength">
    <record name="record" class="com.amig.beanio.Master">
      <field name="master" length="10" />
      <bean name="l1List" collection="list" minOccurs="2" maxOccurs="2" class="com.amig.beanio.Level1">
        <field name="l1" length="10"/>
          <bean name="l2List" collection="list" minOccurs="3" maxOccurs="3" class="com.amig.beanio.Level2">
                  <bean name="l3List" collection="list" minOccurs="2" maxOccurs="2" class="com.amig.beanio.Level3">
                        <field name="l3" length="10"/>
                  </bean>
                <field name="l2" length="10"/>
                  <bean name="l3List" collection="list" minOccurs="2" maxOccurs="2" class="com.amig.beanio.Level3">
                        <field name="l3" length="10"/>
                  </bean>
          </bean>
      </bean>   
      <field name="eof" length="3" padding=" " justify="left"/>
    </record> 
  </stream>

But this does not:
  <stream name="records" format="fixedlength">
    <record name="record" class="com.amig.beanio.Master">
      <field name="master" length="10" />
      <bean name="l1List" collection="list" minOccurs="2" maxOccurs="2" class="com.amig.beanio.Level1">
        <field name="l1" length="10"/>
          <bean name="l2List" collection="list" minOccurs="3" maxOccurs="3" class="com.amig.beanio.Level2">
                <field name="l2" length="10"/>
                  <bean name="l3List" collection="list" minOccurs="2" maxOccurs="2" class="com.amig.beanio.Level3">
                        <field name="l3" length="10"/>
                  </bean>
                <field name="l2" length="10"/>
          </bean>
      </bean>   
      <field name="eof" length="3" padding=" " justify="left"/>
    </record> 
  </stream>

Original comment by cbanner...@gmail.com on 26 Apr 2012 at 7:05

GoogleCodeExporter commented 9 years ago
Fixed for release 1.2.5.

Chet, let me know if the attached snapshot JAR doesn't work for you.  Thanks!

Original comment by kevin.s...@gmail.com on 28 Apr 2012 at 7:10

Attachments:

GoogleCodeExporter commented 9 years ago
Kevin,
Looks like your changes worked. Thank you so much for your quick response!
Chet

Original comment by cbanner...@gmail.com on 1 May 2012 at 4:49

GoogleCodeExporter commented 9 years ago

Original comment by kevin.s...@gmail.com on 19 May 2012 at 3:58