Skip to content

NullPointer Exception on try to parse next fragment (trying to put h2 inside p) #1601

@kokorins

Description

@kokorins

I understand that headers shouldn't be a part of paragraph, but still it should be more explicit in context of code bellow.
If Element is replaced with div or null everything is perfect

Sorry for Kotlin, hope it still readable.

        val bareFragment = "<h2> text </h2>"
        Document("").parser().parseFragmentInput(bareFragment, Element("p"), "")

output:

java.lang.NullPointerException
	at org.jsoup.parser.HtmlTreeBuilderState$7.inBodyStartTag(HtmlTreeBuilderState.java:545)
	at org.jsoup.parser.HtmlTreeBuilderState$7.process(HtmlTreeBuilderState.java:286)
	at org.jsoup.parser.HtmlTreeBuilder.process(HtmlTreeBuilder.java:149)
	at org.jsoup.parser.TreeBuilder.runParser(TreeBuilder.java:76)
	at org.jsoup.parser.HtmlTreeBuilder.parseFragment(HtmlTreeBuilder.java:133)
	at org.jsoup.parser.Parser.parseFragmentInput(Parser.java:53)

Metadata

Metadata

Assignees

Labels

bugA confirmed bug, that we should fix

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions