[M D DLS] Dead store to local variable [DLS_DEAD_LOCAL_STORE]
This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.
Note that Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.
看下面代碼:
public static void main(String args[]) throws Exception{
Object str = new Object() ; //報(bào)錯(cuò)處
str = new Object() ;
System.out.println(str);
}
Object str = new Object();是無用的代碼,因?yàn)樵谙旅嬗幸痪鋝tr= new Object();,很多語言編譯器它都會做優(yōu)化,比如:去除一些無用的代碼以提高效率。JAVA編譯器也會做一些優(yōu)化,但是,Java編譯器對上面這段代碼卻沒有做優(yōu)化(你可以DComplie確認(rèn)一下),編譯后的.class文件還是new了兩次,具體什么原因?qū)е滤蝗プ?/span>這個(gè)優(yōu)化我還不能確定,我覺得難做這種優(yōu)化不是借口,起碼不應(yīng)該是Sun的借口。
修改這段代碼方法很簡單,隨便去掉一行new Object();就可以了。