You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Suresh Srinivas (JIRA)" <ji...@apache.org> on 2012/09/16 23:33:07 UTC

[jira] [Comment Edited] (HADOOP-8814) Inefficient comparison with the empty string. Use isEmpty() instead

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

Suresh Srinivas edited comment on HADOOP-8814 at 9/17/12 8:31 AM:
------------------------------------------------------------------

Comments:
{noformat}
-      if ("".equals(filename) || Path.SEPARATOR.equals(filename)) {
+      if (filename.isEmpty() || Path.SEPARATOR.equals(filename)) {
{noformat}

In this case the previous check {{"".equals(name)}} returned true for only "" and returned false for null. In the new code NPE will be thrown. So please do appropriate changes in the patch.

That said, I agree that {{isEmpty()}} looking at javacode seems to more efficient.
                
      was (Author: sureshms):
    Brandon, I am not sure this is a straight forward change. For example:
{noformat}
-      if ("".equals(filename) || Path.SEPARATOR.equals(filename)) {
+      if (filename.isEmpty() || Path.SEPARATOR.equals(filename)) {
{noformat}

In this case the previous check {{"".equals(filename}}} returned true for only "" and return false for null. In the new code a NPE will be thrown. So please do appropriate changes in the patch.

That said, I agree that isEmpty looking at javacode seems to more efficient.
                  
> Inefficient comparison with the empty string. Use isEmpty() instead
> -------------------------------------------------------------------
>
>                 Key: HADOOP-8814
>                 URL: https://issues.apache.org/jira/browse/HADOOP-8814
>             Project: Hadoop Common
>          Issue Type: Improvement
>          Components: conf, fs, fs/s3, ha, io, metrics, performance, record, security, util
>            Reporter: Brandon Li
>            Assignee: Brandon Li
>            Priority: Minor
>         Attachments: HADOOP-8814.patch
>
>
> Prior to JDK 6, we can check if a string is empty by doing "".equals(s) or s.equals("").
> Starting from JDK 6, String class has a new convenience and efficient method isEmpty() to check string's length.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira