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

Lin Yiqun commented on HDFS-10329:
----------------------------------

Thanks [~xiemaisi] for reporting this. I checked for this, it's true that this 
line {{new StringBuilder('[');}} will just used the method 
{{java.lang.StringBuilder.StringBuilder(int capacity)}} rathan than 
{{java.lang.StringBuilder.StringBuilder(String str)}}. Attach a simple patch 
from me to fix this.

> Bad initialisation of StringBuffer in RequestHedgingProxyProvider.java
> ----------------------------------------------------------------------
>
>                 Key: HDFS-10329
>                 URL: https://issues.apache.org/jira/browse/HDFS-10329
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: ha
>            Reporter: Max Schaefer
>            Assignee: Lin Yiqun
>            Priority: Minor
>
> On [line 
> 167|https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/RequestHedgingProxyProvider.java#L167]
>  of {{RequestHedgingProxyProvider.java}}, a {{StringBuilder}} is initialised 
> like this:
> {code}
> StringBuilder combinedInfo = new StringBuilder('[');
> {code}
> This won't have the (presumably) desired effect of creating a 
> {{StringBuilder}} containing the string {{"["}}; instead, it will create a 
> {{StringBuilder}} with capacity 91 (the character code of '['). See 
> [here|http://what-when-how.com/Tutorial/topic-90315a/Java-Puzzlers-Traps-Pitfalls-and-Corner-Cases-69.html]
>  for an explanation.
> To fix this, pass a string literal instead of the character literal:
> {code}
> StringBuilder combinedInfo = new StringBuilder("[");
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to