I've noticed a strange behavior for the first time, when you extract a docx file and open the numbering.xml, I found that for a certain document that some of the "w:abstractNum" tags are empty, i.e the tag does not contain any "w:lvl" tags. This reflects in a NullPointer exception in the constructor of "ListNumberingDefinition".
What happens is, in the method "initialiseMaps" in class "NumberingDefinitionsPart", there is a loop looping on the HashMap of AbstractNumberings in the object of type Numbering then adds them to the object "abstractListDefinitions" which is of type HashMap of "AbstractListNumberingDefinition". Because of the empty tags, some of those HashMaps are empty.
After that there is a loop on the Num's in the same object of type Numbering, it tries to instantiate an object of type "ListNumberingDefinition", but in the constructor it accesses one of the empty hashmaps and tries to get an entry in it, which causes the null pointer exception.
I was thinking the solution could be to check for the size of the HashMaps before adding them to "abstractListDefinitions", if they're = 0, then they shouldn't be added. This way we could avoid the NullPointer Exception from happening.
Here is the code I'm talking about:
- Code: Select all
// store the abstract list type definitions
for (Numbering.AbstractNum abstractNumNode : numbering.getAbstractNum() )
{
AbstractListNumberingDefinition absNumDef
= new AbstractListNumberingDefinition(abstractNumNode);
abstractListDefinitions.put(absNumDef.getID(), absNumDef);
}
// instantiate the list number definitions
for( Numbering.Num numNode : numbering.getNum() )
{
ListNumberingDefinition listDef
= new ListNumberingDefinition(numNode, abstractListDefinitions);
instanceListDefinitions.put(listDef.getListNumberId(), listDef);
// log.debug("Added list: " + listDef.getListNumberId() );
}
I'm suggesting to check on the size of HashMap of "absNumDef" before adding it to "abstractListDefinitions"
Let me know your thoughts on this please.
Thanks,
Ahmed