亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java - 非空參數的聲納空傳遞

Java - 非空參數的聲納空傳遞

紫衣仙女 2023-08-04 19:09:21
Sonar 在第 17 行標記此后映射,并顯示以下錯誤(Date parsedStartDate = df.parse(startDate);)://Magicservice.controller.MagicStoreController.getTradeMagicsByDateRange(HttpServletRequest, String, String, String) 中java.text.DateFormat.parse(String)的非空參數傳遞Null //此方法調用為非空參數傳遞空值方法參數為空。要么該參數被注釋為應始終為非空的參數,要么分析表明它將始終被取消引用。該代碼已經阻止傳遞空值,不確定這里是否缺少某些內容@PostMapping(value = "/Magics/MagiclistbyDateRange/{MagicStatus}")    public @ResponseBody List<MagicLog> getTradeMagicsByDateRange(HttpServletRequest request,            @PathVariable String MagicStatus, @RequestParam(value = "STARTDATE", required =false ) String startDate,@RequestParam(value = "ENDDATE", required =false) String endDate)            throws ESException {        logger.info("MagicLog received from client -  MagicStatus is :: " + MagicStatus);        String inAppAuthorization = request.getHeader("InAppAuthorization");        validateRequest(request, inAppAuthorization);        List<MagicLog> MagicLogs = new ArrayList<>();        DateFormat df = new SimpleDateFormat("yyyyMMddHH:mm:ss");        df.setLenient(false);        if (startDate == null && endDate==null) {            throw new ESException(MSG_ERROR_NULL_INPUTS);        }        else{        try {            // THIS is the line causing issues (17)            Date parsedStartDate = df.parse(startDate);            //Null passed for non-null parameter of java.text.DateFormat.parse(String) in Magicservice.controller.MagicStoreController.getTradeMagicsByDateRange(HttpServletRequest, String, String, String)            //This method call passes a null value for a non-null method parameter. Either the parameter is annotated as a parameter that should always be non-null, or analysis has shown that it will always be dereferenced.
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

startDate您只處理當和endDate均為空時的情況
相反,您應該處理其中任何一個為空時的情況:

if (startDate == null || endDate==null) { 
           throw new ESException(MSG_ERROR_NULL_INPUTS);
        }


查看完整回答
反對 回復 2023-08-04
  • 1 回答
  • 0 關注
  • 230 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號