@@ -170,22 +170,26 @@ protected void createAndLinkTokenRels(
170
170
@ NonNull final WritableTokenRelationStore tokenRelStore ) {
171
171
// create list of token relations to be added
172
172
final var newTokenRels = createTokenRelsToAccount (account , tokens );
173
- // Link the new token relations to the account
174
- linkTokenRels (account , newTokenRels , tokenRelStore );
175
-
176
- // Now replace the account's old head token number with the new head token number. This is
177
- // how we link the new tokenRels to the account
178
- final var firstOfNewTokenRels = newTokenRels .get (0 );
179
- final var updatedAcct = account .copyBuilder ()
180
- // replace the head token number with the first token number of the new tokenRels
181
- .headTokenId (firstOfNewTokenRels .tokenId ())
182
- // and also update the account's total number of token associations
183
- .numberAssociations (account .numberAssociations () + newTokenRels .size ())
184
- .build ();
185
173
186
- // Save the results
187
- accountStore .put (updatedAcct );
188
- newTokenRels .forEach (tokenRelStore ::put );
174
+ // FUTURE - We may need to return a proper error status when tokens are empty
175
+ if (!newTokenRels .isEmpty ()) {
176
+ // Link the new token relations to the account
177
+ linkTokenRels (account , newTokenRels , tokenRelStore );
178
+
179
+ // Now replace the account's old head token number with the new head token number. This is
180
+ // how we link the new tokenRels to the account
181
+ final var firstOfNewTokenRels = newTokenRels .get (0 );
182
+ final var updatedAcct = account .copyBuilder ()
183
+ // replace the head token number with the first token number of the new tokenRels
184
+ .headTokenId (firstOfNewTokenRels .tokenId ())
185
+ // and also update the account's total number of token associations
186
+ .numberAssociations (account .numberAssociations () + newTokenRels .size ())
187
+ .build ();
188
+
189
+ // Save the results
190
+ accountStore .put (updatedAcct );
191
+ newTokenRels .forEach (tokenRelStore ::put );
192
+ }
189
193
}
190
194
191
195
/**
0 commit comments