[ 
https://issues.apache.org/jira/browse/TIKA-4975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18128530#comment-18128530
 ] 

ASF GitHub Bot commented on TIKA-4975:
--------------------------------------

Copilot commented on code in PR #3353:
URL: https://github.com/apache/tika/pull/3353#discussion_r4308409878


##########
tika-detectors/tika-detector-magika/pom.xml:
##########
@@ -51,7 +51,7 @@
       <groupId>${project.groupId}</groupId>
       <artifactId>tika-serialization</artifactId>
       <version>${project.version}</version>
-      <scope>test</scope>
+      <scope>provided</scope>

Review Comment:
   `MagikaDetector` now invokes `TikaObjectMapperFactory` during static 
initialization, including for default/programmatic construction. `provided` 
does not supply serialization to downstream applications, so consumers using 
this detector and `tika-core` without separately adding serialization fail with 
`NoClassDefFoundError` before detection starts. Use compile scope.



##########
tika-detectors/tika-detector-siegfried/pom.xml:
##########
@@ -39,7 +39,7 @@
       <groupId>${project.groupId}</groupId>
       <artifactId>tika-serialization</artifactId>
       <version>${project.version}</version>
-      <scope>test</scope>
+      <scope>provided</scope>

Review Comment:
   `SiegfriedDetector` now invokes `TikaObjectMapperFactory` during static 
initialization, including for default/programmatic construction. `provided` 
does not supply serialization to downstream applications, so consumers using 
this detector and `tika-core` without separately adding serialization fail with 
`NoClassDefFoundError` before detection starts. Use compile scope.



##########
tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java:
##########
@@ -83,9 +83,8 @@
 
 class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
     private static final Logger LOG = 
LoggerFactory.getLogger(TikaGrpcServerImpl.class);
-    private static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
-            
.defaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL,
 JsonInclude.Include.NON_NULL))
-            .build();
+    private static final ObjectMapper OBJECT_MAPPER = 
TikaObjectMapperFactory.createPlainMapper()

Review Comment:
   `buildRequestParseContext` uses this mapper to read `parse_context_json`. 
The plain mapper silently collapses duplicate configuration keys during 
`readTree`, before `resolveAll` can validate them. Use a strict mapper for that 
initial read so gRPC requests follow the new duplicate-key policy, and add a 
regression test for this entry point.



##########
tika-langdetect/tika-langdetect-lingo24/pom.xml:
##########
@@ -46,6 +46,12 @@
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>tika-serialization</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>

Review Comment:
   `Lingo24LangDetector` now calls `TikaObjectMapperFactory` to read service 
responses, even without JSON component configuration. `provided` leaves this 
dependency out of downstream runtime classpaths, so consumers using this module 
and `tika-core` without separately adding serialization encounter 
`NoClassDefFoundError`. Use compile scope.



##########
tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaResource.java:
##########
@@ -246,7 +247,7 @@ public static String detectFilename(MultivaluedMap<String, 
String> httpHeaders)
      * @throws IOException if parsing fails
      */
     public static void mergeParseContextFromConfig(String configJson, 
ParseContext context) throws IOException, TikaConfigException {
-        ObjectMapper mapper = new ObjectMapper();
+        ObjectMapper mapper = TikaObjectMapperFactory.createPlainMapper();

Review Comment:
   This reads component configuration with a plain data mapper. Duplicate keys 
in a multipart `config` part are silently collapsed by `readTree` before 
`readParseContext` or the strict configuration readers can reject them, 
contrary to the new duplicate-key policy. Use a strict mapper for this initial 
read and add a request-level regression test.



##########
tika-parsers/tika-parsers-ml/tika-vlm/pom.xml:
##########
@@ -81,7 +81,7 @@
       <groupId>${project.groupId}</groupId>
       <artifactId>tika-serialization</artifactId>
       <version>${project.version}</version>
-      <scope>test</scope>
+      <scope>provided</scope>

Review Comment:
   All three VLM parsers now initialize static mappers through 
`TikaObjectMapperFactory`, even when constructed with Java config objects. This 
`provided` declaration overrides the ML parent's compile-scoped serialization 
dependency, leaving standalone consumers without the required class and causing 
`NoClassDefFoundError` during parser initialization. Use compile scope.



##########
tika-translate/pom.xml:
##########
@@ -41,6 +41,12 @@
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>tika-serialization</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>

Review Comment:
   The translators now call `TikaObjectMapperFactory` when reading ordinary API 
responses. `provided` does not propagate this dependency to downstream 
applications, so consumers using `tika-core` and `tika-translate` without 
separately adding `tika-serialization` now encounter `NoClassDefFoundError`. 
Use compile scope for this new runtime requirement.



##########
tika-langdetect/tika-langdetect-mitll-text/pom.xml:
##########
@@ -41,6 +41,12 @@
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>tika-serialization</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>

Review Comment:
   `TextLangDetector` now calls `TikaObjectMapperFactory` when reading language 
lists and detection responses. With `provided` scope, consumers using this 
module and `tika-core` without separately adding `tika-serialization` encounter 
`NoClassDefFoundError` on those paths. Use compile scope to propagate the 
required runtime dependency.



##########
tika-pipes/tika-pipes-core/src/main/java/org/apache/tika/pipes/core/serialization/JsonFetchEmitTupleList.java:
##########
@@ -40,7 +41,7 @@ public class JsonFetchEmitTupleList {
     /** Envelope key: the body must be {"tuples":[...]}; a bare array is 
rejected. */
     public static final String TUPLES = "tuples";
 
-    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+    private static final ObjectMapper OBJECT_MAPPER = 
TikaObjectMapperFactory.createPlainMapper();

Review Comment:
   `fromJson` reads the entire tuple envelope, including `parseContext`, into a 
tree with this plain mapper. Duplicate configuration keys are already collapsed 
when the restricted deserializer receives that tree, so later strict readers 
cannot reject them. Use a strict mapper at the initial read and cover duplicate 
keys inside a tuple's `parseContext`.





> Read component configuration JSON only through tika-serialization's hardened 
> readers
> ------------------------------------------------------------------------------------
>
>                 Key: TIKA-4975
>                 URL: https://issues.apache.org/jira/browse/TIKA-4975
>             Project: Tika
>          Issue Type: Task
>            Reporter: Tim Allison
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to