Claus Ibsen created CAMEL-27304:
-----------------------------------
Summary: camel-tika - parse with tikaParseOutputFormat=html fails
on a document without a title on JDK 21+
Key: CAMEL-27304
URL: https://issues.apache.org/jira/browse/CAMEL-27304
Project: Camel
Issue Type: Bug
Components: camel-tika
Reporter: Claus Ibsen
Fix For: 4.24.0
With {{tikaParseOutputFormat=html}}, {{TikaProducer}} (line 192) wraps the JDK
{{TransformerHandler}} in Tika's {{ExpandedTitleContentHandler}}. For an empty
{{<title>}}, that handler calls {{characters(new char[0], 0, 1)}} and catches
the {{ArrayIndexOutOfBoundsException}} it expects from the serializer (the
TIKA-725 workaround). The JDK serializer ({{ToStream$CharacterBuffer}}) does
not throw: it buffers one NUL character and rejects it when the element ends.
So any document without a title fails:
{noformat}
TIKA-237: Illegal SAXException ... An invalid XML character (Unicode: 0x0) was
found in the node's character data content
{noformat}
Reproduced on Camel 4.24.0-SNAPSHOT (Tika 4.1.0) with JDK 21 and JDK 25:
* plain text, or HTML without a {{<title>}}, to {{html}}: fails;
* the same to {{text}} or {{xml}}: works ({{xml}} writes {{<title/>}});
* HTML with a {{<title>}} to {{html}}: works.
A standalone program with only tika-core 4.1.0 and the JDK serializer shows the
same: it fails on JDK 21 and 25, and on JDK 17 it writes the invalid
{{<title>�</title>}}. Tika's own
{{org.apache.tika.sax.ToHTMLContentHandler}} writes {{<title></title>}}
correctly.
Found through the {{tika-extract-text-action}} Kamelet: extracting text and
then HTML in one route fails at the second call, because the extracted text has
no title. The existing tests ({{TikaParseTest}},
{{TikaMetadataHeaderFilterTest}}) always use documents with a title.
Expected: {{html}} works for documents without a title, for example by using
{{ToHTMLContentHandler}} or a wrapper that does not depend on the serializer
throwing, plus a test with a document that has no title.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)