You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2021/03/18 03:47:02 UTC

[GitHub] [storm] dbgp2021 opened a new pull request #3388: [STORM-3753] Change String.getBytes() to DFSUtil.string2Bytes(String)…

dbgp2021 opened a new pull request #3388:
URL: https://github.com/apache/storm/pull/3388


   … to avoid Unsupported Encoding Exception
   
   Hello,
   I found that DFSUtil.string2Bytes(String) can be used here instead of String.getBytes(). Otherwise, the API String.getBytes() may cause potential risk of UnsupportedEncodingException since the behavior of this method when the string cannot be encoded in the default charset is unspecified.
   One recommended API is DFSUtil.string2Bytes(String) which provides more control over the encoding process and can avoid this exception.
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] Ethanlm commented on a change in pull request #3388: [STORM-3753] Change String.getBytes() to DFSUtil.string2Bytes(String)…

Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3388:
URL: https://github.com/apache/storm/pull/3388#discussion_r600715583



##########
File path: external/storm-eventhubs/src/main/java/org/apache/storm/eventhubs/spout/ZookeeperStateStore.java
##########
@@ -60,7 +61,7 @@ public void close() {
     @Override
     public void saveData(String statePath, String data) {
         data = data == null ? "" : data;
-        byte[] bytes = data.getBytes();
+        byte[] bytes = DFSUtil.string2Bytes(data);

Review comment:
       I prefer to not introduce hadoop dependencies just for this single function since its implementation is really simple 
   https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java#L273
   https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java#L114-L120
   
   This `DFSUtil.string2Bytes(data)` method  is basically equivalent to `data.getBytes(StandardCharsets.UTF_8.name());`. 
   
   Can you explain more about the issues you have encountered and maybe provide a test case? 
   
   Thanks
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [storm] dbgp2021 commented on pull request #3388: [STORM-3753] Change String.getBytes() to DFSUtil.string2Bytes(String)…

Posted by GitBox <gi...@apache.org>.
dbgp2021 commented on pull request #3388:
URL: https://github.com/apache/storm/pull/3388#issuecomment-817502349


   
   Hi @Ethanlm , thanks for your recommendation, I have changed the code correspondingly, which use data.getBytes(xxx). Please review.
   
   Currently, I do not have a test case for this, but a very similar one can be found here: https://github.com/apache/hadoop/commit/ab3885f2c8cfd63ff94e548c40db3b4ea52c12e8 .
   
   I believe that providing the encoding is a good way to make the code more robust.
   
   Please kindly check. Thanks.
   
   
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org