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


##########
components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java:
##########
@@ -153,7 +159,7 @@ private void putObject(Exchange exchange, 
ClientConfigurations clientConfigurati
         } else if (body instanceof String) {
             // the string content will be stored in the remote object
             LOG.trace("Writing text body into an object");
-            InputStream stream = new ByteArrayInputStream(((String) 
body).getBytes());
+            InputStream stream = new ByteArrayInputStream(((String) 
body).getBytes(StandardCharsets.UTF_8));
             putObjectResult = 
obsClient.putObject(clientConfigurations.getBucketName(),
                     clientConfigurations.getObjectName(), stream);
             stream.close();

Review Comment:
   🔎 **Low — stream not in try-with-resources (consistency):** `stream.close()` 
is called manually; if `obsClient.putObject()` throws, `close()` is skipped. 
For a `ByteArrayInputStream` wrapping a byte array, `close()` is a no-op per 
JDK spec — so there is no actual OS-resource leak here today. However, this is 
inconsistent with the try-with-resources approach the PR introduces in 
`OBSUtils`, and if the body type handling ever evolves (e.g. wrapping a real 
`InputStream`), the pattern will silently leak. A minimal fix:
   
   ```suggestion
               try (InputStream stream = new ByteArrayInputStream(((String) 
body).getBytes(StandardCharsets.UTF_8))) {
                   putObjectResult = 
obsClient.putObject(clientConfigurations.getBucketName(),
                           clientConfigurations.getObjectName(), stream);
               }
   ```



-- 
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