Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchElementException #732

Closed
fcorneli opened this issue Jun 30, 2021 · 2 comments
Closed

NoSuchElementException #732

fcorneli opened this issue Jun 30, 2021 · 2 comments

Comments

@fcorneli
Copy link

On one of our templates, we could trigger the following exception:

java.util.NoSuchElementException
	at java.util.LinkedList.getLast(LinkedList.java:257)
	at com.openhtmltopdf.layout.LayoutContext.getBlockFormattingContext(LayoutContext.java:257)
	at com.openhtmltopdf.layout.LayoutContext.translate(LayoutContext.java:306)
	at com.openhtmltopdf.newtable.TableBox.calcPageClearance(TableBox.java:562)
	at com.openhtmltopdf.newtable.TableBox.layout(TableBox.java:227)
	at com.openhtmltopdf.layout.Layer.layoutAbsoluteChild(Layer.java:1027)
	at com.openhtmltopdf.layout.Layer.layoutAbsoluteChildren(Layer.java:949)
	at com.openhtmltopdf.layout.Layer.finish(Layer.java:931)
	at com.openhtmltopdf.layout.LayoutContext.popLayer(LayoutContext.java:292)
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:1107)
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:984)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.layout(PdfBoxRenderer.java:347)
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:45)
@fcorneli
Copy link
Author

If I do something quick-and-dirty like:

diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/LayoutContext.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/LayoutContext.java
index 990f1c10..d2d4bc0d 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/LayoutContext.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/LayoutContext.java
@@ -51,6 +51,7 @@ import com.openhtmltopdf.render.FSFont;
 import com.openhtmltopdf.render.FSFontMetrics;
 import com.openhtmltopdf.render.MarkerData;
 import com.openhtmltopdf.render.PageBox;
+import java.util.NoSuchElementException;
 
 /**
  * This class tracks state which changes over the course of a layout run.
@@ -303,7 +304,11 @@ public class LayoutContext implements CssContext {
     }
 
     public void translate(int x, int y) {
-        getBlockFormattingContext().translate(x, y);
+        try {
+            getBlockFormattingContext().translate(x, y);
+        } catch (NoSuchElementException e) {
+
+        }
     }
 
     /* code to keep track of all of the id'd boxes */

it no longer fails of course, but I don't see my page footer anymore.

@danfickle
Copy link
Owner

Hi @fcorneli,

It turns out that the layout for table boxes was not aware of stacking context layers or block formatting contexts (both required for position: absolute). I have now fixed. In the meantime, you can use a surrounding div with the position: absolute style rather than putting that style directly on the table.

Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants