[英]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.