This is an automated email from the ASF dual-hosted git repository.
tilman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new f11a42c76 TIKA-4485: fix relative files + test
f11a42c76 is described below
commit f11a42c7636d1e8c0cb1dde1fa7ca092ca8f9218
Author: Tilman Hausherr <[email protected]>
AuthorDate: Tue Sep 16 08:56:31 2025 +0200
TIKA-4485: fix relative files + test
---
.../java/org/apache/tika/config/TikaConfig.java | 2 +-
.../java/org/apache/tika/config/TikaConfigTest.java | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
index 065419b79..14ff21b11 100644
--- a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
+++ b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
@@ -364,7 +364,7 @@ public class TikaConfig {
InputStream stream = null;
try {
stream = new URI(config).toURL().openStream();
- } catch (IOException | URISyntaxException ignore) {
+ } catch (IOException | URISyntaxException | IllegalArgumentException
ignore) {
}
if (stream == null) {
stream = serviceLoader.getResourceAsStream(config);
diff --git a/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
b/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
index b89491414..97ff3f376 100644
--- a/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
+++ b/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
@@ -176,6 +176,27 @@ public class TikaConfigTest extends AbstractTikaConfigTest
{
assertNotNull(resources.get("custom-mimetypes.xml"));
}
+ /**
+ * TIKA-4485: try a relative path with an empty constructor.
+ *
+ * @throws Exception
+ */
+ @Test
+ void testEmptyConstructor() throws Exception {
+ // file that exists
+ System.setProperty("tika.config",
"src/test/resources/org/apache/tika/config/TIKA-1445-default-except.xml");
+ TikaConfig tikaConfig = new TikaConfig();
+ // code from the TIKA-1445 test
+ CompositeParser cp = (CompositeParser) tikaConfig.getParser();
+ List<Parser> parsers = cp.getAllComponentParsers();
+ assertEquals(3, parsers.size());
+
+ // file that doesn't exist
+ System.setProperty("tika.config", "doesntexist.xml");
+ TikaException ex = assertThrows(TikaException.class, () -> new
TikaConfig());
+ assertTrue(ex.getMessage().contains("Specified Tika configuration not
found: doesntexist.xml"));
+ }
+
/**
* TIKA-1445 It should be possible to exclude DefaultParser from
* certain types, so another parser explicitly listed will take them