最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】docbook中,用fop生成pdf出错:java.lang.ArrayIndexOutOfBoundsException

Docbook crifan 2215浏览 0评论

【问题】

docbook源码写好了,可以正常编译为html。

也可以编译为fo了,但是使用fop从fo中生成pdf却出错:

严重: Exception
org.apache.fop.apps.FOPException: -1
java.lang.ArrayIndexOutOfBoundsException: -1
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
        at org.apache.fop.text.linebreak.LineBreakUtils.getLineBreakPairProperty(LineBreakUtils.java:744)
        at org.apache.fop.text.linebreak.LineBreakStatus.nextChar(LineBreakStatus.java:178)
        at org.apache.fop.layoutmgr.inline.TextLayoutManager.getNextKnuthElements(TextLayoutManager.java:641)
        at org.apache.fop.layoutmgr.inline.LineLayoutManager.collectInlineKnuthElements(LineLayoutManager.java:639)
        at org.apache.fop.layoutmgr.inline.LineLayoutManager.getNextKnuthElements(LineLayoutManager.java:579)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.FlowLayoutManager.getNextChildElements(FlowLayoutManager.java:199)
        at org.apache.fop.layoutmgr.FlowLayoutManager.addChildElements(FlowLayoutManager.java:140)
        at org.apache.fop.layoutmgr.FlowLayoutManager.addChildElements(FlowLayoutManager.java:129)
        at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements(FlowLayoutManager.java:70)
        at org.apache.fop.layoutmgr.PageBreaker.getNextKnuthElements(PageBreaker.java:216)
        at org.apache.fop.layoutmgr.AbstractBreaker.getNextBlockList(AbstractBreaker.java:692)
        at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:149)
        at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:132)
        at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:337)
        at org.apache.fop.layoutmgr.PageBreaker.doLayout(PageBreaker.java:85)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:107)
        at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:238)
        at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:120)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:349)
        at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177)
        at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1101)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.endElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
        … 3 more

———

java.lang.ArrayIndexOutOfBoundsException: -1
        at org.apache.fop.text.linebreak.LineBreakUtils.getLineBreakPairProperty(LineBreakUtils.java:744)
        at org.apache.fop.text.linebreak.LineBreakStatus.nextChar(LineBreakStatus.java:178)
        at org.apache.fop.layoutmgr.inline.TextLayoutManager.getNextKnuthElements(TextLayoutManager.java:641)
        at org.apache.fop.layoutmgr.inline.LineLayoutManager.collectInlineKnuthElements(LineLayoutManager.java:639)
        at org.apache.fop.layoutmgr.inline.LineLayoutManager.getNextKnuthElements(LineLayoutManager.java:579)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:571)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextChildElements(BlockStackingLayoutManager.java:552)
        at org.apache.fop.layoutmgr.BlockStackingLayoutManager.getNextKnuthElements(BlockStackingLayoutManager.java:280)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:123)
        at org.apache.fop.layoutmgr.BlockLayoutManager.getNextKnuthElements(BlockLayoutManager.java:115)
        at org.apache.fop.layoutmgr.FlowLayoutManager.getNextChildElements(FlowLayoutManager.java:199)
        at org.apache.fop.layoutmgr.FlowLayoutManager.addChildElements(FlowLayoutManager.java:140)
        at org.apache.fop.layoutmgr.FlowLayoutManager.addChildElements(FlowLayoutManager.java:129)
        at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements(FlowLayoutManager.java:70)
        at org.apache.fop.layoutmgr.PageBreaker.getNextKnuthElements(PageBreaker.java:216)
        at org.apache.fop.layoutmgr.AbstractBreaker.getNextBlockList(AbstractBreaker.java:692)
        at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:149)
        at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:132)
        at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:337)
        at org.apache.fop.layoutmgr.PageBreaker.doLayout(PageBreaker.java:85)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:107)
        at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:238)
        at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:120)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:349)
        at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177)
        at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1101)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.endElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)

../../../config/docbook.mk:370: recipe for target `../output/pdf/interrupt_related.pdf’ failed
make: *** [../output/pdf/interrupt_related.pdf] Error 1

 

【解决过程】

1.去看了下所生成的html,很正常,但是却看到一个很特殊的字符:

ǥ֐ύ

所以,真的是有点怀疑是这个特殊字符造成的错误。

以为是不小心对于xml编码转换所照成的字符异常呢,结果去此xml内容的来源的word文件中一看,原来本身word中就是此特殊字符的。

2.ArrayIndexOutOfBoundsException字面意思是,数组的索引号超出边界了。所以去找找fo或者源码中,哪里可能产生数组的地方。

3.结果网上也找到了有人遇到类似错误:

ArrayIndexOutOfBoundsException in LineBreakUtils with LATIN CAPITAL LETTER SHARP S

所以,就去删除那个特殊字符试试。

结果的确就解决了此看似怪异的问题,可以正常编译出来pdf了。

【总结】

此处出现的java.lang.ArrayIndexOutOfBoundsException,org.apache.fop.text.linebreak.LineBreakUtils.getLineBreakPairProperty方面的错误,是由于一个特殊字符照成的。

如果不是(细心地)碰巧发现了,还真的很难找到具体原因的。

总之,以后写docbook源码的时候,只能再仔细一点,以尽量避免此类问题,别无更好的办法了。

 


【后记】

后来看了上面帖子:

ArrayIndexOutOfBoundsException in LineBreakUtils with LATIN CAPITAL LETTER SHARP S

中的讨论,其是通过把fop从从0.95升级到1.0而解决的此问题。

但是其实我此处的fop本身就已经是1.0了,但是还是出现了此问题。

按理来说,是不应该出现这类问题的。

毕竟,如果本身在UTF-8编码的xml的已经输入了该字符,不论该字符如何特殊,毕竟只要在Unicode范围内,那么就应该可以正常的生成fo文件,而fop也就应该正常的从fo文件生成pdf才对,而不应该出现此错误才对。

然后去看了下,上面那个特殊字符“ǥ֐ύ”所对应的十六进制是:

c7 a5 d6 90 cf 8d

Notepad++中,也是无法显示出对应字符,而显示的是乱码和问号的。

但是还是觉得既然能在UTF-8的xml中输入了,那么就不应该出现此问题才对。

有待高手来深入解释。

转载请注明:在路上 » 【已解决】docbook中,用fop生成pdf出错:java.lang.ArrayIndexOutOfBoundsException

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.185 seconds, using 22.05MB memory