Skip to content

Commit f35c23a

Browse files
committed
Call setter with Collection argument only after Collection has been
fully populated This closes #266
1 parent 43aa6f4 commit f35c23a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Xpp3ReaderGenerator.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
715715

716716
String adder;
717717

718+
boolean requireSetter = false;
719+
718720
if ( wrappedItems )
719721
{
720722
sc.add( tagComparison );
@@ -735,7 +737,7 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
735737
}
736738
sc.add( associationType + " " + associationName + " = " + defaultValue + ";" );
737739

738-
sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" );
740+
requireSetter = true;
739741

740742
adder = associationName + ".add";
741743
}
@@ -789,8 +791,8 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
789791

790792
sc.add( associationName + " = " + defaultValue + ";" );
791793

792-
sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" );
793-
794+
requireSetter = true;
795+
794796
sc.unindent();
795797
sc.add( "}" );
796798

@@ -848,15 +850,15 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
848850

849851
sc.unindent();
850852
sc.add( "}" );
851-
852-
sc.unindent();
853-
sc.add( "}" );
854853
}
855-
else
854+
855+
if (requireSetter)
856856
{
857-
sc.unindent();
858-
sc.add( "}" );
857+
sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" );
859858
}
859+
sc.unindent();
860+
sc.add( "}" );
861+
860862
}
861863
else
862864
{
@@ -870,7 +872,7 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
870872
if ( locationTracker != null )
871873
{
872874
sc.add( locationTracker.getName() + " " + LOCATION_VAR + "s;" );
873-
writeNewSetLocation( field, objectName, LOCATION_VAR + "s", sc );
875+
writeNewLocation( LOCATION_VAR + "s", sc );
874876
}
875877

876878
if ( xmlAssociationMetadata.isMapExplode() )
@@ -954,7 +956,7 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata,
954956
sc.unindent();
955957
sc.add( "}" );
956958
}
957-
959+
writeSetLocation( field, objectName, LOCATION_VAR + "s", sc );
958960
sc.unindent();
959961
sc.add( "}" );
960962
}
@@ -1659,6 +1661,11 @@ private String buildNewLocation( String source )
16591661
+ ( ( sourceTracker != null ) ? ", " + source : "" ) + " )";
16601662
}
16611663

1664+
private void writeSetLocation( ModelField field, String objectName, String trackerVariable, JSourceCode sc )
1665+
{
1666+
writeSetLocation( "\"" + field.getName() + "\"", objectName, trackerVariable, sc );
1667+
}
1668+
16621669
private void writeSetLocation( String key, String objectName, String trackerVariable, JSourceCode sc )
16631670
{
16641671
if ( locationTracker == null )

0 commit comments

Comments
 (0)