DLS_DEAD_LOCAL_STORE

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值給一個區域變數,但這個值卻從來沒被用過。

如果確定這個值會由後面的程式assign,那初始時就值接給null。

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();
        }