Community
Participate
Working Groups
There is no null check when an ArrayList is constructed from the choice of values. As a result an NPE is thrown and it becomes impossible to customize a property view by using a select if there is a choice of values, I had to resort to a Java service which catches the NPE and returns null. Code (org.eclipse.sirius.ext.emf.edit.EditingDomainService line 549): public List<?> getPropertyDescriptorChoiceOfValues(EObject self, String featureName) { IItemPropertyDescriptor desc = getPropertyDescriptorForFeature(self, featureName); if (desc != null) { return new ArrayList<>(desc.getChoiceOfValues(self)); // The culprit line } else { return null; } } Proposed fix: public List<?> getPropertyDescriptorChoiceOfValues(EObject self, String featureName) { IItemPropertyDescriptor desc = getPropertyDescriptorForFeature(self, featureName); if (desc != null) { Collection<Object> choices = desc.getChoiceOfValues(self); return choices == null ? null : new ArrayList<>(choices); } else { return null; } }
Thanks for the bug report. This looks like a no-brainer, we'll try to include this in the next maintenance release (for which we do not have a date yet). I'd rather return an empty lis than null when getChoiceOfValues() returns null (which propagates the risk of NPE to the callers). Do you see a reason to explicitly distinguish between null and an empty list here?
Hello, Null and empty list have different semantics in EMF.Edit. Null means no constraints - any value - text field. Empty list means no choices - default value. Therefore, it shall be null. There isn't much risk in returning null, IMO, as there is already an execution path that returns null - the last return if desc is null.
New Gerrit change created: https://git.eclipse.org/r/156165
Sorry for the delay. You're right of course. https://git.eclipse.org/r/156165 should fix this.
Fixed by 495ec1d8b15ff28e904370e8a939311d05a9245c.
Gerrit change https://git.eclipse.org/r/156165 was merged to [master]. Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=495ec1d8b15ff28e904370e8a939311d05a9245c
The test added for this NPE is OK (https://ci.eclipse.org/sirius/job/sirius.tests-master/PLATFORM=2019-12,SUITE=junit,jdk=oracle-jdk8-latest,label=migration/lastCompletedBuild/testReport/org.eclipse.sirius.tests.unit.common/EditingDomainServicesTest/avoid_npe_when_no_choiceOfValues/)
Available in Sirius 6.3.1 (part of Eclipse 2020-06). See https://wiki.eclipse.org/Sirius/6.3.1 for details on the release.