This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-22695f59-0119-4aaa-a9e6-65083d6b9d40 XWIKI-23526 Open

Calling BaseClass#removeField(name) on a field and then BaseClass#addField(name, field) does not remove the field from the fields to remove list

 
View issue   ·   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-df9abe51-cd3c-4125-bbf1-d4a77680fff5 Raphaël Jakse created this issue on 12/Sep/25 12:22
 
Summary: Calling BaseClass#removeField(name) on a field and then BaseClass#addField(name, field) does not remove the field from the fields to remove list
Issue Type: cid:jira-generated-image-avatar-22695f59-0119-4aaa-a9e6-65083d6b9d40 Bug
Affects Versions: 17.7.0
Assignee: Unassigned
Components: Old Core
Created: 12/Sep/25 12:22
Priority: cid:jira-generated-image-static-major-14b3f6b1-6306-4c0f-8fae-828a5e22f9da Major
Reporter: Raphaël Jakse
Description:

When someone removes a field from a class by calling BaseClass#removeField(name), and then adds this field back by calling BaseClass#addField(name, field), the field is added to fieldsToRemove by #removeField but not removed from it by addField, which can lead to issues.

A workaround is to notice this and use getFieldsToRemove and #setFieldsToRemove. Documentation for these methods should probably be added to make it clear how they should be used and what for, including the fact that one can add or remove a field by modifying the returned list (i.e. getFieldsToRemove does not return a (immutable) copy of the list.

By the way, is this list strictly necessary? Should it be indeed public?