Skip to content

TIKA-4752-follow-up - #2871

Merged
tballison merged 6 commits into
mainfrom
TIKA-4752-follow-up
Jun 5, 2026
Merged

TIKA-4752-follow-up#2871
tballison merged 6 commits into
mainfrom
TIKA-4752-follow-up

Conversation

@tballison

Copy link
Copy Markdown
Contributor

Thanks for your contribution to Apache Tika! Your help is appreciated!

Before opening the pull request, please verify that

  • there is an open issue on the Tika issue tracker which describes the problem or the improvement. We cannot accept pull requests without an issue because the change wouldn't be listed in the release notes.
  • the issue ID (TIKA-XXXX)
    • is referenced in the title of the pull request
    • and placed in front of your commit messages surrounded by square brackets ([TIKA-XXXX] Issue or pull request title)
  • commits are squashed into a single one (or few commits for larger changes)
  • Tika is successfully built and unit tests pass by running ./mvnw clean test
  • there should be no conflicts when merging the pull request branch into the recent main branch. If there are conflicts, please try to rebase the pull request branch on top of a freshly pulled main branch
  • if you add new module that downstream users will depend upon add it to relevant group in tika-bom/pom.xml.

We will be able to faster integrate your pull request if these conditions are met. If you have any questions how to fix your problem or about using Tika in general, please sign up for the Tika mailing list. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR follows up on TIKA-4752 by improving how Apache Tika determines character encodings from declared metadata and container-specific signals (notably ZIP entry name UTF-8 declarations), and by aligning some parsers to use the configurable/default encoding detector chain.

Changes:

  • Teach ZipParser to honor ZIP UTF-8 declarations via the Unicode extra field and to pass the EFS flag as a CONTENT_TYPE_HINT into charset detection.
  • Extend MetadataCharsetDetector to consult TikaCoreProperties.CONTENT_TYPE_HINT (between CONTENT_TYPE and CONTENT_ENCODING) and add focused tests.
  • Update DBFParser and OutlookExtractor to prefer an EncodingDetector from ParseContext with a DefaultEncodingDetector fallback.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tika-parsers/.../ZipEntryNameEncodingTest.java Adds regression tests covering ZIP entry-name UTF-8 declarations (EFS flag and Unicode extra field).
tika-parsers/.../ZipParser.java Updates entry-name resolution to trust Unicode extra fields and to feed EFS as a metadata hint into detection.
tika-parsers/.../DBFParser.java Switches DBF charset detection to use ParseContext’s EncodingDetector with a default fallback.
tika-parsers/.../OutlookExtractor.java Refactors 7-bit charset guessing to use EncodingDetector on raw body bytes with declared charset as a hint.
tika-core/.../MetadataCharsetDetectorTest.java Adds tests for CONTENT_TYPE_HINT and precedence ordering across metadata keys.
tika-core/.../MetadataCharsetDetector.java Implements CONTENT_TYPE_HINT handling and updates documentation accordingly.
Comments suppressed due to low confidence (1)

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/dbf/DBFParser.java:152

  • In getCharset(), the try-with-resources stream tis is created but the detector is invoked on a fresh TikaInputStream.get(bytes) instead. This bypasses the managed resource and can leak/duplicate streams. Also, when detection returns an empty list, the current code sets charset to null, which can later trigger an NPE when charset.toString() is called in parse(); it should fall back to the existing DEFAULT_CHARSET instead.
            try (TikaInputStream tis = TikaInputStream.get(bytes)) {
                List<EncodingResult> results =
                        detector.detect(TikaInputStream.get(bytes), new Metadata(), parseContext);
                charset = results.isEmpty() ? null : results.get(0).getCharset();
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread tika-core/src/main/java/org/apache/tika/detect/MetadataCharsetDetector.java Outdated
tballison and others added 2 commits June 5, 2026 12:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
# Conflicts:
#	tika-core/src/main/java/org/apache/tika/detect/MetadataCharsetDetector.java
@tballison
tballison merged commit d66da4f into main Jun 5, 2026
4 checks passed
@tballison
tballison deleted the TIKA-4752-follow-up branch September 3, 2026 21:47
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

Successfully merging this pull request may close these issues.

2 participants