amitprasadom / java-wikipedia-parser

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

NPE when parsing simple input #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run this code:
    Parser.toHtml("*[[Evoliucija]]\n", new SmartLinkResolver() {
      public String resolve(String arg0) {
        return "http://foo.com";
      }
    });

2. I get this exception:
Exception in thread "main" java.lang.NullPointerException
    at
be.devijver.wikipedia.parser.ast.UnorderedListItem.toString(UnorderedListItem.ja
va:17)
    at
be.devijver.wikipedia.parser.ast.parser.DefaultASTParser.doInvokeParseMethod(Def
aultASTParser.java:31)
    at
be.devijver.wikipedia.parser.ast.parser.AbstractASTParser.invokeParseMethod(Abst
ractASTParser.java:350)
    at
be.devijver.wikipedia.parser.ast.parser.AbstractASTParser.parseDocument(Abstract
ASTParser.java:62)
    at
be.devijver.wikipedia.parser.ast.parser.AbstractASTParser.parse(AbstractASTParse
r.java:52)
    at be.devijver.wikipedia.Parser.toHtml(Parser.java:32)
    at be.devijver.wikipedia.TestBug.main(TestBug.java:9)

What version of the product are you using? On what operating system?

version 0.1 with Java 1.6.0

Please provide any additional information below.

Original issue reported on code.google.com by dan80...@gmail.com on 15 Mar 2008 at 4:52

GoogleCodeExporter commented 8 years ago
I was able to reproduce this error and trace the source to:

  be.divijver.wikipedia.parser.wikitext.MarkupParser

The code at line 231 in the parseContentList() method should be changed from:

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

to:

  if (!characters.isEmpty())
    contentList.add(new Characters(asString(characters)));
  return (Content [])contentList.toArray(new Content[contentList.size()]);

Without this change it is possible to return NULL content and the
NullPointerException you discovered will result.

Original comment by bodhi.r...@gmail.com on 11 Dec 2008 at 9:22

GoogleCodeExporter commented 8 years ago
Actually, the following works better.  (The first one inserts empty paragraphs 
for
newlines)

if (!characters.isEmpty())
  contentList.add(new Characters(asString(characters)));

if (contentList.size() > 0)
  return (Content [])contentList.toArray(new Content[contentList.size()]);
else
  return null;

Original comment by bodhi.r...@gmail.com on 16 Dec 2008 at 7:05