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

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

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


##########
tika-core/src/main/java/org/apache/tika/io/FilenameUtils.java:
##########
@@ -400,7 +400,7 @@ public static String calculateExtension(Metadata metadata, 
String defaultValue)
         if (ext != null) {
             return ext;
         }
-        return ".bin";
+        return defaultValue;

Review Comment:
   This is a behavior change: callers that previously relied on the implicit 
`.bin` fallback for unknown MIME types will now get their provided 
`defaultValue` (or possibly `null` if they passed null). If backward 
compatibility matters, consider either (a) keeping `.bin` as the fallback when 
`defaultValue` is null/blank, or (b) updating method/Javadoc to explicitly 
document how `defaultValue == null` is handled and adding a small guard to 
preserve a stable default.



##########
tika-core/src/test/java/org/apache/tika/io/FilenameUtilsTest.java:
##########
@@ -245,6 +245,12 @@ public void testEmbeddedFilePaths() throws Exception {
 
     }
 
+@Test
+public void testCalculateExtensionUnknownValue() {
+    assertEquals(".pdf", FilenameUtils.calculateExtension(
+            getMetadata("the quick brown fox", "application/x-tika-unknown"), 
".pdf"));
+}

Review Comment:
   The test is missing the indentation used by surrounding methods in this 
class (the `@Test` annotation and method start at column 0). Please align 
formatting/indentation with the rest of the file to keep the test class 
consistent.





> FilenameUtils.calculateExtension ignores defaultValue on unknown path
> ---------------------------------------------------------------------
>
>                 Key: TIKA-4882
>                 URL: https://issues.apache.org/jira/browse/TIKA-4882
>             Project: Tika
>          Issue Type: Bug
>          Components: core
>            Reporter: Tim Grein
>            Priority: Minor
>
> FilenameUtils.calculateExtension ignores an unknown extension in the sense 
> that the behavior on an unknown extension is not specified in the javadoc and 
> it's not explicitly handled. It should probably be either handled or 
> explicitly documented.



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

Reply via email to