View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002671 | NoesisGUI | Unity3D | public | 2023-08-22 06:40 | 2023-08-23 18:19 |
Reporter | ckfinite | Assigned To | sfernandez | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 3.2.1 | ||||
Target Version | 3.2.2 | Fixed in Version | 3.2.2 | ||
Summary | 0002671: EventTrigger can fail with a nullreferenceexception without an explanatory error message | ||||
Description | The implementation of EventTrigger's RegisterEvent does not gracefully handle the case where SourceObject is null but the given event does not exist on the source. In this case, the conditionals fall through and pass a null to IsValidEvent which chokes with a NullReferenceException. A more informative error message should be produced instead. | ||||
Steps To Reproduce | The implementation of EventTrigger's RegisterEvent method, as follows [code] private void RegisterEvent(object source, string eventName) { if (source != null && !string.IsNullOrEmpty(eventName)) { Type type = source.GetType(); EventInfo ev = type.GetEvent(eventName); if (ev == null) { if (SourceObject != null) { throw new ArgumentException(string.Format( "EventTrigger cannot find event '{0}' in SourceObject '{1}'", eventName, type)); } } if (!IsValidEvent(ev)) { if (SourceObject != null) { throw new ArgumentException(string.Format( "SourceObject event '{0}' is not valid for EventTrigger", eventName)); } } else { _event = ev; _handler = Delegate.CreateDelegate(ev.EventHandlerType, this, OnEventMethod); _event.AddEventHandler(source, _handler); } } } [/code] doesn't properly handle the case where the default target object (usually AssociatedObject) exists but the designated event does not while no SourceObject is set (and thus SourceObject == null). As described above, this code will fall through with a null ev and null SourceObject and pass IsValidEvent null, which fails with a nullreferenceexception. An additional branch should be added to the condition to provide an informative message in this case. | ||||
Tags | No tags attached. | ||||
Platform | Any | ||||
Solved in r12660 with the following patch:Index: EventTriggerBase.cs =================================================================== --- EventTriggerBase.cs (revision 12659) +++ EventTriggerBase.cs (revision 12660) @@ -171,8 +171,7 @@ eventName, type)); } } - - if (!IsValidEvent(ev)) + else if (!IsValidEvent(ev)) { if (SourceObject != null) { |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2023-08-22 06:40 | ckfinite | New Issue | |
2023-08-22 17:14 | jsantos | Assigned To | => sfernandez |
2023-08-22 17:14 | jsantos | Status | new => assigned |
2023-08-23 18:17 | sfernandez | Product Version | 3.2 => 3.2.1 |
2023-08-23 18:17 | sfernandez | Target Version | => 3.2.2 |
2023-08-23 18:19 | sfernandez | Status | assigned => resolved |
2023-08-23 18:19 | sfernandez | Resolution | open => fixed |
2023-08-23 18:19 | sfernandez | Fixed in Version | => 3.2.2 |
2023-08-23 18:19 | sfernandez | Note Added: 0008661 |