ArrayList<RouteOperateVO> routeOperateVOS = new ArrayList<>(); try { Example example = Example.builder(RoutePO.class).where(Sqls.custom().andIn("waybillNo", wayBillNos)).build(); List<RoutePO> routePOList = routePOMapper.selectByExample(example); for (RoutePO routePO : routePOList) { if(null != routePO){ RouteOperateVO routeOperateVO = new RouteOperateVO(); BeanUtils.copyProperties(routePO,routeOperateVO); if (null !=routePO.getOriginCountryId()){ routeOperateVO.setOriginCountry(routePO.getOriginCountryId()); } if (null !=routePO.getTargetCountryId()){ routeOperateVO.setTargetCountry(routePO.getTargetCountryId()); } if (null !=routePO.getOriginCountryId()){ routeOperateVO.setOccurCountry(routePO.getOccurCountryId()); } if (null != routePO.getRouteType()){ routeOperateVO.setRouteTypeDesc(RouteTypeEnum.fromType(routePO.getRouteType()).getDesc()); } if (StringUtils.isNotBlank(routePO.getOperateBy())){ CommonResponse<UserBO> commonResponse = userServiceFeign.selectUserInfoByUserId(Integer.parseInt(routePO.getOperateBy())); if (commonResponse.isSuccess()){ UserBO userBO = commonResponse.getData(); routeOperateVO.setOperatorName(userBO.getEnName() == null ?userBO.getCnName() :userBO.getEnName()); } } routeOperateVOS.add(routeOperateVO); } } } catch (Exception e) { log.error("查询数据库异常:{}", e); } return routeOperateVOS; 分析这段代码可能出现的空指针异常
时间: 2024-02-14 12:35:55 浏览: 61
这段代码可能出现空指针异常的情况有以下几种:
1. 当wayBillNos为null时,在andIn("waybillNo", wayBillNos)方法中会抛出空指针异常。
2. 在for循环中,如果routePOList中有为null的元素,会抛出空指针异常。
3. 在BeanUtils.copyProperties(routePO,routeOperateVO)中,如果routePO为null,会抛出空指针异常。
4. 在setOriginCountry、setTargetCountry、setOccurCountry、setRouteTypeDesc、setOperatorName方法中,如果参数为null,会抛出空指针异常。
5. 在userServiceFeign.selectUserInfoByUserId方法中,如果传入的参数为null或空字符串,会抛出空指针异常。
综上所述,这段代码可能出现的空指针异常需要注意以上几种情况。
阅读全文