gnodet-bot commented on code in PR #28540:
URL: https://github.com/apache/camel/pull/28540#discussion_r4383949601


##########
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java:
##########
@@ -186,6 +181,20 @@ public void putObject(MinioClient minioClient, final 
Exchange exchange) throws E
         }
     }
 
+    /**
+     * The length of the body when it is known without reading it (such as a 
file, java.nio.file.Path, byte[], String or

Review Comment:
   💡 **Javadoc inaccuracy:** `String` is listed as a type whose length is 
*"known without reading it"*, but `PayloadHelper.getLength(String)` returns -1 
— the length is only known after the body is converted to a 
`ByteArrayInputStream` (which `getLength(InputStream)` can then measure). 
Consider removing `String` from the list, or clarifying that String falls 
through to the inputStream path.



##########
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java:
##########
@@ -152,15 +152,10 @@ public void putObject(MinioClient minioClient, final 
Exchange exchange) throws E
                 if (object instanceof File file) {
                     filePayload = file;
                     inputStream = new FileInputStream(filePayload);
-                    if (contentLength <= 0) {
-                        contentLength = filePayload.length();
-                    }
+                    contentLength = bodyLength(filePayload, inputStream, 
contentLength);
                 } else {
-                    if (contentLength <= 0) {
-                        // such as a java.nio.file.Path, byte[] or stream cache
-                        contentLength = PayloadHelper.getLength(object);
-                    }
                     inputStream = 
exchange.getMessage().getMandatoryBody(InputStream.class);
+                    contentLength = bodyLength(object, inputStream, 
contentLength);
                     if (contentLength <= 0) {
                         contentLength = PayloadHelper.getLength(inputStream);

Review Comment:
   ⚠️ **Dead code:** `bodyLength()` already called 
`PayloadHelper.getLength(inputStream)` internally (line 193 of the new method). 
If it returned `contentLength` (the header fallback), both `getLength(body)` 
and `getLength(inputStream)` already returned < 0, so calling 
`getLength(inputStream)` again here will always return -1. This block can be 
removed (keep the cache-stream fallback below if needed, but the `getLength` 
redundancy should go).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to