簡體   English   中英

未經檢查的投射由FindBugs抱怨

[英]Unchecked casting complain by FindBugs

請考慮以下代碼:

 public void broadcast(FacesEvent event)
    throws AbortProcessingException {

    if(!(event instanceof WrapperEvent)) {
      super.broadcast(event);
      return;
    }

    // Sets up the correct context and fire our wrapped event.
    GridWrapperEvent revent = (GridWrapperEvent)event; // FindBugs is complaining here 
    int oldRowIndex = getRowIndex();
    int oldColumnIndex = getColumnIndex();
    boolean oldClientIdRewritting = clientIdRewritting;
    setClientIdRewritting(revent.isClientIdRewritting());

    setActiveCell(revent.getRowIndex(), revent.getColumnIndex());

    FacesEvent rowEvent = revent.getFacesEvent();
    rowEvent.getComponent().broadcast(rowEvent);
    setActiveCell(oldRowIndex, oldColumnIndex);
    setClientIdRewritting(oldClientIdRewritting);
  }

FindBugs抱怨注釋行。 我能做些什么嗎? 這就是FindBugs所說的:

未選中/未確認的強制轉換此未強制轉換,並非所有類型的實例都可以強制轉換為其強制類型。 確保您的程序邏輯確保此強制轉換不會失敗。

如果您知道event將始終是GridWrapperEvent ,則可以忽略該警告。 否則你可以將一個強制轉換(以及依賴它的邏輯)包裝在一個支票中

if (event instanceof GridWrapperEvent) {
  // ...
}

實際上你已經這樣做了,但對於(我假設)更通用的WrapperEvent類。 也許您可以調整該檢查而不是添加新檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM