gpt4 book ai didi

java - 为什么我在 Flying Saucer 中的柜台上突然出现 NPE?

转载 作者:行者123 更新时间:2023-12-01 17:58:09 25 4
gpt4 key购买 nike

我有一个 html 模板,自去年 11 月以来我一直将其与 Flying Saucer PDF 一起使用。我最近重建了该项目,突然相同的 HTML 和相同的代码抛出了 NPE。我将范围缩小到页面计数器。当我删除它们时,它就起作用了。这是我的 html 示例,演示了该问题。

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">

@page {
@top-right {
content: element(header);
}
}
#pagenumber:before {
content: counter(page);
}

#pagecount:before {
content: counter(pages);
}

</style>
</head>

<body>
<header id="header" class="clearfix">

<div class="page-header">
<span class="label">Order Status</span><br/>
Page <div id="pagenumber"></div> of <div id="pagecount"></div>
</div>
</header>

<div>Hello World</div>
</body>
</html>

我将其作为有效负载发送到一个小型网络服务,该服务使用 Flying Saucer 来渲染它并将其发回。这是我在服务中的代码:

@RequestMapping(value="/render", method= RequestMethod.POST)
public void renderPdf(@RequestBody String xhtmlContent, HttpServletResponse response) {

ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(xhtmlContent);
renderer.layout(); //ERROR HAPPENS HERE

try {
response.addHeader("Content-disposition", "attachment;filename=invoice.pdf");
response.setContentType("application/x-octet-stream");
renderer.createPDF(response.getOutputStream());
} catch (Exception e) {
logger.error("Error creating pdf: ", e);
}

}

我得到以下堆栈跟踪:

java.lang.NullPointerException: null
at org.xhtmlrenderer.layout.breaker.Breaker.getLanguage(Breaker.java:136) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.getBreakPointsProvider(Breaker.java:124) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.doBreakText(Breaker.java:147) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.breakText(Breaker.java:112) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.InlineBoxing.layoutText(InlineBoxing.java:848) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.InlineBoxing.layoutContent(InlineBoxing.java:201) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutInlineChildren(BlockBox.java:983) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:964) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:229) ~[flying-saucer-pdf-9.1.4.jar:na]
at com.byrne.pdfprinter.pdf.PdfController.renderPdf(PdfController.java:26) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_112]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_112]

再次,让我重申一下,在我尝试重建它之前,这段代码是有效的。我没有更改我的 Flying Saucer 版本,但我在 Maven 中使用 RELEASE 作为我的版本。因此,为了确保没有问题,我指定了具体的版本号,可以追溯到它工作时的日期以及之前的一段时间,但它仍然会发生。

当我发布这篇文章时,我正在追踪源头,但还没有找到任何东西。

最佳答案

Flying Saucer 项目9.1.5版本修复了该问题。9.1.4 是罪魁祸首。

关于java - 为什么我在 Flying Saucer 中的柜台上突然出现 NPE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com