amitprasadom / java-wikipedia-parser

Automatically exported from code.google.com/p/java-wikipedia-parser
0 stars 0 forks source link

list not finishing with character throws exception #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use MainClass.java from trunk
2. set wikitext = "* [[X]], [[Y]]" + "\nZ";
3. run app

What is the expected output? What do you see instead?
expected: <div><ul><li><a href="SMARTLINK:X">X</a>, <a 
href="SMARTLINK:Y">Y</a></li></ul><p>Z</p></div>
(NB SMARTLINK is my dummy SmartLinkResolver)
instead:
Exception in thread "main" java.lang.NullPointerException
    at be.devijver.wikipedia.parser.ast.UnorderedListItem.toString(UnorderedListItem.java:16)

Please provide any additional information below.

This exception is thrown when there is no character at the end of the list
I copy/pasting here my patch.

in MarkupParser.java method public Content[] parseContentList()

TRUNK VERSION

if (currentCharacter == '\n') {
    if (!characters.isEmpty()) {
        contentList.add(new Characters(asString(characters)));
        return (Content[])contentList.toArray(new Content[contentList.size()]);
    } else {
        return null;
    }
}

PATCHED VERSION

if (currentCharacter == '\n') 
{
    if (!characters.isEmpty()) 
        contentList.add(new Characters(asString(characters)));                  
    if (!contentList.isEmpty())
        return (Content[]) contentList
                .toArray(new Content[contentList.size()]);                  
    return null;                    
} 

Original issue reported on code.google.com by adrianvintu@gmail.com on 29 Jul 2010 at 8:07