Repository: nvaccess/nvda

Issue:
A lot of garbageHandler errors in Internet Explorer controls after merge of 11782

### Steps to reproduce:
1. Open Internet Explorer.
2. Go to http://test-cases.tink.uk/aria-current/
3. Switch to focus mode.
4. Start tabbing around.
### Actual behavior:
After a few focus changes the error sound is played and something similar to the log entry below is in the log viewer:
```
DEBUGWARNING - NVDAObjects.IAccessible.MSHTML.MSHTML._get_isCurrent (21:26:14.624) - MainThread (6216):
Unknown aria-current value: None
DEBUGWARNING - NVDAObjects.IAccessible.MSHTML.MSHTML._get_isCurrent (21:26:15.044) - MainThread (6216):
Unknown aria-current value: None
DEBUGWARNING - NVDAObjects.IAccessible.MSHTML.MSHTML._get_isCurrent (21:26:15.054) - MainThread (6216):
Unknown aria-current value: None
DEBUGWARNING - NVDAObjects.IAccessible.MSHTML.MSHTML._get_isCurrent (21:26:15.064) - MainThread (6216):
Unknown aria-current value: None
DEBUGWARNING - NVDAObjects.IAccessible.MSHTML.MSHTML._get_isCurrent (21:26:16.265) - MainThread (6216):
Unknown aria-current value: None
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Garbage collector has found one or more unreachable objects. See further warnings for specific objects.
Stack trace:
  File "nvda.pyw", line 247, in <module>
  File "core.pyc", line 567, in main
  File "wx\core.pyc", line 2134, in MainLoop
  File "gui\__init__.pyc", line 1067, in Notify
  File "core.pyc", line 537, in run
  File "queueHandler.pyc", line 88, in pumpAll
  File "queueHandler.pyc", line 55, in flushQueue
  File "eventHandler.pyc", line 65, in _queueEventCallback
  File "eventHandler.pyc", line 241, in executeEvent
  File "eventHandler.pyc", line 254, in doPreGainFocus
  File "api.pyc", line 131, in setFocusObject
  File "treeInterceptorHandler.pyc", line 62, in cleanup
  File "baseObject.pyc", line 26, in __get__
  File "virtualBuffers\MSHTML.pyc", line 228, in _get_isAlive
  File "baseObject.pyc", line 42, in __get__
  File "baseObject.pyc", line 146, in _getPropertyViaCache
  File "NVDAObjects\IAccessible\MSHTML.pyc", line 824, in _get_states
  File "comtypesMonkeyPatches.pyc", line 86, in new__getattr__
  File "comtypes\client\dynamic.pyc", line 120, in __getattr__
  File "comtypes\automation.pyc", line 765, in Invoke
  File "comtypesMonkeyPatches.pyc", line 104, in newCpbDel
  File "garbageHandler.pyc", line 64, in notifyObjectDeletion
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c97310 at 6c44d00>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5a6fe64 at 737d8a0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5ca6034 at 737d350>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5ca697c at 737dee0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x07347050>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.425) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c971b0 at 737dd00>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.Button object at 0x07347030>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5a6fef4 at 737d760>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5c90f0c at 737d8f0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5c91074 at 737d990>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x06C5C3B0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5a6fc6c at 737ddf0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5cf507c at 737db70>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5cf54fc at 737d490>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5cf5a0c at 737dbc0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.Dynamic_MSHTMLListIAccessible object at 0x07160FD0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5cf5544 at 737db20>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5cf5b74 at 737d300>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5c917c4 at 7361bc0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5c91bfc at 7361d50>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x07347AB0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5ca634c at 737d7b0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x073479F0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c97470 at 737dd50>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5cf510c at 737dc60>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5ca6034 at 737d670>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5ca697c at 737d3a0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x07160FF0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5c9114c at 7361a80>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5c90f0c at 7361580>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5c91074 at 7361b20>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x073470B0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c91c8c at 7361710>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5cf507c at 73616c0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5cf54fc at 7361530>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5cf5a0c at 7361850>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.Dynamic_MSHTMLListIAccessible object at 0x0717B270>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5cf5544 at 7361a30>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <eventHandler._EventExecuter object at 0x072F2EB0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x07178D70>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x06CE5A50>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c96ff8 at 7056cb0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5c91344 at 7056df0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5ca6034 at 7340030>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5ca697c at 7056f30>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x07347190>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IDispatch) ptr=0x5c91974 at 73403f0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeInfo) ptr=0x5c90f0c at 7340080>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(ITypeComp) ptr=0x5c91074 at 7340580>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <NVDAObjects.IAccessible.MSHTML.MSHTML object at 0x072F2390>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <POINTER(IAccessible) ptr=0x5c9192c at 73402b0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <eventHandler._EventExecuter object at 0x07160E90>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x07342250>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x073423F0>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <eventHandler._EventExecuter object at 0x072F2D10>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x07342F10>
WARNING - garbageHandler.notifyObjectDeletion (21:26:17.435) - MainThread (6216):
Deleting unreachable object <virtualBuffers.MSHTML.MSHTMLTextInfo object at 0x07342230>
ERROR - garbageHandler._collectionCallback (21:26:17.435) - MainThread (6216):
Found at least 57 unreachable objects in run

```

### Expected behavior:
No errors about unreachable objects from garbageHandler.
### System configuration
#### NVDA installed/portable/running from source:
Portable
#### NVDA version:
NVDA version alpha-21746,dcf3a325

#### Windows version:
Windows 7 X64
#### Name and version of other software in use when reproducing the issue:
Internet Explorer 11.0.9600.19596

#### Other information about your system:
I've confirmed with git bisect that this is a regression from #11782

### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
No errors with 2020.4

#### If addons are disabled, is your problem still occuring?
Yes
#### Did you try to run the COM registry fixing tool in NVDA menu / tools?
No



Discussion:
cc @feerrenrut 

Resolving patch:
diff --git a/source/NVDAObjects/IAccessible/MSHTML.py b/source/NVDAObjects/IAccessible/MSHTML.py
--- a/source/NVDAObjects/IAccessible/MSHTML.py
+++ b/source/NVDAObjects/IAccessible/MSHTML.py
@@ -543,14 +543,25 @@ def _get_treeInterceptorClass(self):
 			return virtualBuffers.MSHTML.MSHTML
 		return super(MSHTML,self).treeInterceptorClass
 
-	def _get_isCurrent(self):
-		isCurrent = self.HTMLAttributes["aria-current"]
+	def _get_isCurrent(self) -> controlTypes.IsCurrent:
+		try:
+			isCurrent = self.HTMLAttributes["aria-current"]
+		except LookupError:
+			return controlTypes.IsCurrent.NO
+
+		# key may be in HTMLAttributes with a value of None
+		if isCurrent is None:
+			return controlTypes.IsCurrent.NO
+
 		try:
 			return controlTypes.IsCurrent(isCurrent)
 		except ValueError:
 			log.debugWarning(f"Unknown aria-current value: {isCurrent}")
 			return controlTypes.IsCurrent.NO
 
+	#: Typing for autoproperty _get_HTMLAttributes
+	HTMLAttributes: HTMLAttribCache
+
 	def _get_HTMLAttributes(self):
 		return HTMLAttribCache(self.HTMLNode)
 
diff --git a/source/virtualBuffers/MSHTML.py b/source/virtualBuffers/MSHTML.py
--- a/source/virtualBuffers/MSHTML.py
+++ b/source/virtualBuffers/MSHTML.py
@@ -46,18 +46,26 @@ def _normalizeFormatField(self, attrs):
 			attrs['language']=languageHandler.normalizeLanguage(language)
 		return attrs
 
-	def _normalizeControlField(self,attrs):
-		level=None
-
-		ariaCurrentValue = attrs.get('HTMLAttrib::aria-current', 'false')
+	def _getIsCurrentAttribute(self, attrs: dict) -> controlTypes.IsCurrent:
+		defaultAriaCurrentStringVal = "false"
+		ariaCurrentValue = attrs.get('HTMLAttrib::aria-current', defaultAriaCurrentStringVal)
+		# key 'HTMLAttrib::aria-current' may be in attrs with a value of None
+		ariaCurrentValue = defaultAriaCurrentStringVal if ariaCurrentValue is None else ariaCurrentValue
 		try:
 			ariaCurrent = controlTypes.IsCurrent(ariaCurrentValue)
 		except ValueError:
 			log.debugWarning(f"Unknown aria-current value: {ariaCurrentValue}")
 			ariaCurrent = controlTypes.IsCurrent.NO
+		return ariaCurrent
+
+	# C901 'MSHTMLTextInfo._normalizeControlField' is too complex (42)
+	# Look for opportunities to simplify this function.
+	def _normalizeControlField(self, attrs: dict):  # noqa: C901
+		level = None
 
-		if ariaCurrent != controlTypes.IsCurrent.NO:
-			attrs['current'] = ariaCurrent
+		isCurrent = self._getIsCurrentAttribute(attrs)
+		if isCurrent != controlTypes.IsCurrent.NO:
+			attrs['current'] = isCurrent
 
 		placeholder = self._getPlaceholderAttribute(attrs, 'HTMLAttrib::aria-placeholder')
 		if placeholder:


Test patch: