[mdoc] Fix NullReferenceException when importing @name attribute.
authorJonathan Pryor <jonpryor@vt.edu>
Wed, 14 May 2014 20:04:05 +0000 (16:04 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Wed, 14 May 2014 20:09:10 +0000 (16:09 -0400)
commitc4775a55b80f64f3144c2495e27668785e000906
treee011055cb85328e707273d61edb1912c0c36aa62
parent4d388f07d45698b2ef8a88c3c43cf0938cc5476e
[mdoc] Fix NullReferenceException when importing @name attribute.

(Reported by directhex on #mono 2014-05-14 at 14:28 EDT.)

When importing Microsoft XML Documentation, if a //altmember/@name,
//exception/@name, or //permission/@name attribute is encountered then
mdoc will die with a NullReferenceException:

mdoc: System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.Documentation.MsxdocDocumentationImporter.ImportDocumentation (Mono.Documentation.DocsNodeInfo info)
  at Mono.Documentation.MDocUpdater.MakeDocNode (Mono.Documentation.DocsNodeInfo info)
  at Mono.Documentation.MDocUpdater.UpdateMember (Mono.Documentation.DocsNodeInfo info)
  at Mono.Documentation.MDocUpdater.MakeMember (System.Xml.XmlDocument doc, Mono.Documentation.DocsNodeInfo info)
  at Mono.Documentation.MDocUpdater.DoUpdateType2 (System.String message, System.Xml.XmlDocument basefile, Mono.Cecil.TypeDefinition type, System.String output, Boolean insertSince)
  at Mono.Documentation.MDocUpdater.StubType (Mono.Cecil.TypeDefinition type, System.String output)
  at Mono.Documentation.MDocUpdater.DoUpdateType (Mono.Cecil.TypeDefinition type, System.String basepath, System.String dest)
  at Mono.Documentation.MDocUpdater.DoUpdateAssembly (Mono.Cecil.AssemblyDefinition assembly, System.Xml.XmlElement index_types, System.String source, System.String dest, System.Collections.Generic.HashSet`1 goodfiles)
  at Mono.Documentation.MDocUpdater.DoUpdateAssemblies (System.String source, System.String dest)
  at Mono.Documentation.MDocUpdater.Run (IEnumerable`1 args)
  at Mono.Documentation.MDoc.Run (System.String[] args)
  at Mono.Documentation.MDoc.Main (System.String[] args)

The cause of the NullReferenceException is due to inconsistent
checking: we check that _either_ `child.Attributes["cref"]` OR
`child.Attributes["name"]` is not null, and if one of them IS non-null
then we just grab `child.Attributes["cref"].Value`, which will throw a
NullReferenceException if the @name attribute was present but not the
@cref attribute.

The fix is to be consistent: once we grab an XmlAttribute, use the
already looked up XmlAttribute, don't re-look it up.
mcs/tools/mdoc/Mono.Documentation/monodocer.cs
mcs/tools/mdoc/Test/DocTest-v1.cs
mcs/tools/mdoc/Test/en.expected.importslashdoc/Mono.DocTest/UseLists.xml
mcs/tools/mdoc/Test/html.expected/Mono.DocTest/UseLists.html
mcs/tools/mdoc/Test/msxdoc-expected.importslashdoc.xml