Open Chumhoo opened 6 years ago
Bug location: ASE/Hotel/src/main/java/database/DatabaseHandler.java (line 66)
Type: Controversial
Code snippet:
Bug: Found 'DU'-anomaly for variable 'result' (lines '69'-'77').
Explanation: DU anomaly is defined as a recently defined variable turns to be undefined[1]. In this case, the variable ‘result’ brings about this anomaly. In this block of code, ‘result’ is declared before the try block, assigned in the try block, returned at the very end. If a SQLexception is caught, the ‘result’ variable is never used. Thus, it would sufficient that the declaration and assignment written as one line of code in the try block[2].
References: [1] https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#dataflowanomalyanalysis [2] https://stackoverflow.com/questions/16718514/pmd-dd-du-anomaly