请考虑以下代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
FindBugs抱怨注释行.我能做些什么吗?这就是FindBugs所说的:
未选中/未确认的 强制转换此未强制转换,并非所有类型的实例都可以强制转换为其强制类型.确保您的程序逻辑确保此强制转换不会失败.
如果你知道这event将永远是一个GridWrapperEvent,你可以忽略警告.否则你可以将一个强制转换(以及依赖它的逻辑)包装在一个支票中
if (event instanceof GridWrapperEvent) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
实际上你已经这样做了,但对于(我假设)更通用的WrapperEvent类.也许您可以调整该检查而不是添加新检查.
| 归档时间: |
|
| 查看次数: |
8368 次 |
| 最近记录: |