代码之家  ›  专栏  ›  技术社区  ›  Karn_way

StringUtils.isNotEmpty(str)似乎无法在hadoop集群数据验证中正常工作

  •  0
  • Karn_way  · 技术社区  · 11 年前

    我不确定,并面临如下奇怪的空指针问题。有人可以在下面的代码中帮助我吗

     if ((COUNTRY_CODE.equalsIgnoreCase(Country.TEST.name())) && (strCellId.matches("[0-9]*")))
    

    正在日志文件中抛出空指针(根据行号)。我能看到的唯一违规代码是 strCellId.matches("[0-9]*") 如果 strCellId 为空

    然而 StringUtils.isNotEmpty(strCellId) 在我们进入if条件之前已调用。请看情况

    public static boolean validateCellId(String strCellId)
    {
      if (StringUtils.isNotEmpty(strCellId)) {
         //here the nullpointer is coming  
        if ((COUNTRY_CODE.equalsIgnoreCase(Country.TEST.name())) && (strCellId.matches("[0-9]*"))) {
          return true;
        }
      }
    
      return false;
    }
    
    1 回复  |  直到 11 年前
        1
  •  0
  •   Karn_way    11 年前

    这是我的错。 @zsxwing你是对的。我的国家没有初始化,我应该检查一下,我只是满怀信心地忽略了它。谢谢