[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();是無(wú)用的代碼,因?yàn)樵谙旅嬗幸痪鋝tr= new Object();,很多語(yǔ)言編譯器它都會(huì)做優(yōu)化,比如:去除一些無(wú)用的代碼以提高效率。JAVA編譯器也會(huì)做一些優(yōu)化,但是,Java編譯器對(duì)上面這段代碼卻沒(méi)有做優(yōu)化(你可以DComplie確認(rèn)一下),編譯后的.class文件還是new了兩次,具體什么原因?qū)е滤蝗プ?/span>這個(gè)優(yōu)化我還不能確定,我覺(jué)得難做這種優(yōu)化不是借口,起碼不應(yīng)該是Sun的借口。
修改這段代碼方法很簡(jiǎn)單,隨便去掉一行new Object();就可以了。