Description
DLS: Dead store to status
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.
Assign值給一個區域變數,但這個值卻從來沒被用過。
Solution
如果確定這個值會由後面的程式assign,那初始時就值接給null。
Example
Before:
JSONArray jsonArray = new JSONArray(); if( option == OK ){ jsonArray = genOkResult(); } else if( option == WARNING ){ jsonArray = genWarnResult(); } else { jsonArray = genDefaultResult(); }
After:
JSONArray jsonArray = null; if( option == OK ){ jsonArray = genOkResult(); } else if( option == WARNING ){ jsonArray = genWarnResult(); } else { jsonArray = genDefaultResult(); }
留言
張貼留言