From b5ee982bc70edfb5238d828e3078768d14a621bf Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Wed, 31 May 2017 12:07:20 +0200
Subject: [PATCH] Added extra null checks to event registration, caused an
exception when clicking around during full resync
---
.../AcaciaZPushPlugin/ZPush/ZPushFolder.cs | 38 ++++++++++++-------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushFolder.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushFolder.cs
index 6da41a1..87bcb8a 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushFolder.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushFolder.cs
@@ -61,9 +61,9 @@ namespace Acacia.ZPush
protected override void DoRelease()
{
Cleanup();
- _folder.Dispose();
- _items.Dispose();
- _subFolders.Dispose();
+ _folder?.Dispose();
+ _items?.Dispose();
+ _subFolders?.Dispose();
}
public override string ToString()
@@ -113,24 +113,36 @@ namespace Acacia.ZPush
if (register)
{
// Item events
- _items.ItemAdd += Items_ItemAdd;
- _items.ItemChange += Items_ItemChange;
+ if (_items != null)
+ {
+ _items.ItemAdd += Items_ItemAdd;
+ _items.ItemChange += Items_ItemChange;
+ }
// Folder events
- _subFolders.FolderAdd += SubFolders_FolderAdd;
- _subFolders.FolderRemove += SubFolders_FolderRemove;
- _subFolders.FolderChange += SubFolders_FolderChange;
+ if (_subFolders != null)
+ {
+ _subFolders.FolderAdd += SubFolders_FolderAdd;
+ _subFolders.FolderRemove += SubFolders_FolderRemove;
+ _subFolders.FolderChange += SubFolders_FolderChange;
+ }
}
else
{
// Item events
- _items.ItemAdd -= Items_ItemAdd;
- _items.ItemChange -= Items_ItemChange;
+ if (_items != null)
+ {
+ _items.ItemAdd -= Items_ItemAdd;
+ _items.ItemChange -= Items_ItemChange;
+ }
// Folder events
- _subFolders.FolderAdd -= SubFolders_FolderAdd;
- _subFolders.FolderRemove -= SubFolders_FolderRemove;
- _subFolders.FolderChange -= SubFolders_FolderChange;
+ if (_subFolders != null)
+ {
+ _subFolders.FolderAdd -= SubFolders_FolderAdd;
+ _subFolders.FolderRemove -= SubFolders_FolderRemove;
+ _subFolders.FolderChange -= SubFolders_FolderChange;
+ }
}
}