jsoup icon indicating copy to clipboard operation
jsoup copied to clipboard

Fix NullPointerException in case a custom document is passed to W3CDom

Open casid opened this issue 1 year ago • 1 comments

When we provide a custom output Document to W3CDom#convert, we receive a NullPointerException in the W3CBuilder constructor.

I've added a test that demonstrates the behavior. Here's the stacktrace from that test without the applied fix.

java.lang.NullPointerException: Cannot invoke "org.jsoup.nodes.Element.ownerDocument()" because "this.contextElement" is null

	at org.jsoup.helper.W3CDom$W3CBuilder.<init>(W3CDom.java:364)
	at org.jsoup.helper.W3CDom.convert(W3CDom.java:250)
	at org.jsoup.helper.W3CDom.convert(W3CDom.java:238)
	at org.jsoup.helper.W3CDomTest.canConvertToCustomDocument(W3CDomTest.java:199)

casid avatar Feb 01 '24 11:02 casid

Hi @jhy,

did you get a chance to have a look at this already?

It is not urgent, but it prevents us from upgrading to the latest JSOUP version without hacking the classpath.

Thank you so much!

casid avatar Apr 23 '24 09:04 casid

Great, TY!

jhy avatar Jul 01 '24 06:07 jhy

Thank you @jhy!

casid avatar Jul 02 '24 11:07 casid