Add type check for DataObjectSearchResultItem#1941
Conversation
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR hardens IconService::getClassIcon() by guarding the call to getClassDefinitionIcon() with an instanceof DataObjectSearchResultItem check. Since getClassIcon() accepts a DataObjectSearchResultItem|DataObject union, and getClassDefinitionIcon() is only defined on DataObjectSearchResultItem, invoking it on a plain DataObject (e.g. a Concrete object or folder that falls through the first branch) would trigger a runtime error. The short-circuiting && ensures the method is only reached for supported types, which is a correct and well-targeted fix that preserves existing behavior for search-result items.
Changes:
- Added an
instanceof DataObjectSearchResultItemguard before accessinggetClassDefinitionIcon()ingetClassIcon().



Pull Request Overview
This PR fixes an issue in
IconService::getClassIcon()wheregetClassDefinitionIcon()could be called on objects that do not support the method.Changes
instanceof DataObjectSearchResultItemcheck before accessinggetClassDefinitionIcon().getClassDefinitionIcon()on unsupported objects.Before
After
Why?
getClassIcon()may receive different object types, butgetClassDefinitionIcon()is only available onDataObjectSearchResultItem. This guard ensures the method is invoked only when supported, making the service more robust and preventing unexpected errors.