88import org .jsoup .nodes .Element ;
99import org .jsoup .nodes .Node ;
1010
11+ import javax .annotation .Nullable ;
1112import java .util .ArrayList ;
1213
1314import static org .jsoup .internal .StringUtil .inSorted ;
@@ -123,7 +124,7 @@ boolean process(Token t, HtmlTreeBuilder tb) {
123124 if (name .equals ("base" ) && el .hasAttr ("href" ))
124125 tb .maybeSetBaseUri (el );
125126 } else if (name .equals ("meta" )) {
126- Element meta = tb .insertEmpty (start );
127+ tb .insertEmpty (start );
127128 // todo: charset switches
128129 } else if (name .equals ("title" )) {
129130 handleRcData (start , tb );
@@ -842,7 +843,6 @@ else if (!tb.onStack(formatEl)) {
842843 tb .replaceOnStack (node , replacement );
843844 node = replacement ;
844845
845- //noinspection StatementWithEmptyBody
846846 if (lastNode == furthestBlock ) {
847847 // move the aforementioned bookmark to be immediately after the new node in the list of active formatting elements.
848848 // not getting how this bookmark both straddles the element above, but is inbetween here...
@@ -855,14 +855,16 @@ else if (!tb.onStack(formatEl)) {
855855 lastNode = node ;
856856 }
857857
858- if (inSorted (commonAncestor .normalName (), Constants .InBodyEndTableFosters )) {
859- if (lastNode .parent () != null )
860- lastNode .remove ();
861- tb .insertInFosterParent (lastNode );
862- } else {
863- if (lastNode .parent () != null )
864- lastNode .remove ();
865- commonAncestor .appendChild (lastNode );
858+ if (commonAncestor != null ) { // safety check, but would be an error if null
859+ if (inSorted (commonAncestor .normalName (), Constants .InBodyEndTableFosters )) {
860+ if (lastNode .parent () != null )
861+ lastNode .remove ();
862+ tb .insertInFosterParent (lastNode );
863+ } else {
864+ if (lastNode .parent () != null )
865+ lastNode .remove ();
866+ commonAncestor .appendChild (lastNode );
867+ }
866868 }
867869
868870 Element adopter = new Element (formatEl .tag (), tb .getBaseUri ());
0 commit comments