Skip to content

Fix NullReferenceException in NUIGadgetManager#7653

Open
upple wants to merge 3 commits into
Samsung:mainfrom
upple:dev/NUIGadget
Open

Fix NullReferenceException in NUIGadgetManager#7653
upple wants to merge 3 commits into
Samsung:mainfrom
upple:dev/NUIGadget

Conversation

@upple

@upple upple commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Description of Change

  • Wrap UIGadgetInfo.CreateUIGadgetInfo with try/catch and log packageId on exception
  • Add try/catch in UIGadgetManager static constructor to prevent TypeInitializationException
  • Add try/catch in foreach loop to continue loading other packages on failure
  • Add try/catch in UIGadgetManager.Refresh() with packageId in error logs
  • Add try/catch in NUIGadgetManager static constructor, LoadGadgetInfos, and Refresh

API Changes

  • ACR: N/A

@upple upple requested review from hjhun and pjh9216 as code owners May 20, 2026 05:44
@github-actions github-actions Bot added the API15 label May 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the robustness of the UIGadget components by implementing extensive try-catch blocks, improved null safety for application paths, and more detailed logging during initialization and resource loading. Feedback focuses on preventing a potential native resource leak in CreateUIGadgetInfo using a finally block, adopting safer casting for CoreApplication.Current, and removing several redundant null checks and exception handlers to streamline the implementation.

Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs Outdated
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs Outdated
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs Outdated
Comment thread src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs Outdated
- Wrap UIGadgetInfo.CreateUIGadgetInfo with try/catch and log packageId on exception
- Add try/catch in UIGadgetManager static constructor to prevent TypeInitializationException
- Add try/catch in foreach loop to continue loading other packages on failure
- Add try/catch in UIGadgetManager.Refresh() with packageId in error logs
- Add try/catch in NUIGadgetManager static constructor, LoadGadgetInfos, and Refresh

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
- Use 'as' cast instead of direct cast for CoreApplication.Current with null check
- Remove redundant outer try/catch in foreach loops (CreateUIGadgetInfo already handles exceptions internally)
- Move PackageInfoDestroy to finally block for proper native handle cleanup
- Remove redundant null check after 'new NUIGadgetInfo' operator

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs Outdated
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs Outdated
- Remove try/catch from CreateUIGadgetInfo (keep finally for native handle cleanup)
- Let exceptions propagate to UIGadgetManager which handles them
- Remove outer try/catch from static constructor
- Add try/catch inside foreach loops in static constructor and Refresh()
- Revert CoreApplication.Current as cast (not related to original issue)
- Revert defensive try/catch in NUIGadgetManager (not related to original issue)

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>

@upple upple left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjhun
Thank you for the reveiw.
Please review again.

Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs Outdated
Comment thread src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs Outdated
@JoonghyunCho

Copy link
Copy Markdown
Member

🤖 [AI Review]

Reviewed — no findings.

Scope checked:

  • UIGadgetInfo.CreateUIGadgetInfo refactored to try/finally — fixes the native-handle leak when any of the SetResourceType / SetResourceVersion / SetMetadata calls throw. PackageInfoDestroy(handle) now runs unconditionally; handle remains valid until finally because the unmanaged calls in the try body don't depend on it being already destroyed.
  • Moving SetExecutableFile / SetResourceFile / SetResourceClassName / SetResourcePath / SetUIGadgetResourcePath inside the try block is benign — they take only info, not handle, so timing relative to PackageInfoDestroy is irrelevant.
  • UIGadgetManager widens catch (ArgumentNullException || OverflowException) to catch (Exception) around per-package CreateUIGadgetInfo calls — defensible in a foreach-over-packages loop where one bad package should not stop the others; each failure is logged with packageId for diagnosis. No callers above rely on specific exception types here.
  • NUIGadgetManager.LoadGadgetInfos drops the redundant if (gadgetInfo != null) check — new NUIGadgetInfo(info) either throws or returns non-null, so the guard was unreachable.
  • No public API changes; all touched types/members are internal or non-public-surface — no XML-doc obligations.

No 🔴 critical issues, no 🟡 suggestions to flag.


Automated review — final merge decision rests with human reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants