Skip to content

xpp3-reader: set method called before list is populated #266

Closed
@kwin

Description

@kwin

With the goal xpp3-reader the set method of the bean is called before the collection has been populated. For example the following pattern is generated:

java.util.List<MojoDescriptor> mojos = new java.util.ArrayList<MojoDescriptor>();
pluginDescriptor.setMojos( mojos );
while ( parser.nextTag() == XmlPullParser.START_TAG )
{
    if ( "mojo".equals( parser.getName() ) )
    {
        mojos.add( parseMojoDescriptor( parser, strict ) );
    }
    else
    {
        checkUnknownElement( parser, strict );
    }
}

when using the following model:

<field xdoc.separator="blank">
  <name>mojos</name>
  <version>1.0.0+</version>
  <association>
    <type>MojoDescriptor</type>
    <multiplicity>*</multiplicity>
  </association>
  <description>Description of each Mojo provided by the plugin.</description>
</field>

The code fails if the called setter method does not just add the reference to the collection but copies/processes the given argument.
Therefore the setter method should be called only after population (i.e. after the while loop).
The code is being generated in

private void writeNewSetLocation( String key, String objectName, String trackerVariable, JSourceCode sc )
.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions