walkmod / walkmod-core

walkmod: an open source tool to fix coding style issues
http://www.walkmod.com
GNU Lesser General Public License v3.0
154 stars 23 forks source link

sonar:RemoveUselessVariables is not working #69

Closed subisueno closed 7 years ago

subisueno commented 7 years ago

Steps to reproduce -

  1. Open cmd prompt > go to project directory > type command and press enter key > walkmod apply sonar:RemoveUselessVariables

  2. Project has a sample Java class for removing Unused Variable - package sonar.autofix;

public class MyServiceImpl {

private String name;// unused
private int id;// unused

}

Expected Output - Code Transformation Chain should result in "SUCCESS" and unused variables should get automatically removed.

Actual Output - Unused variables are not removed. Below Console output produced -

 INFO [main] - THE TRANSFORMATION CHAIN sonar:RemoveUselessVariables STARTS 
--------------------------------------------------------------------------------

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
 INFO [main] - No sources changed

 INFO [main] - TRANSFORMATION CHAIN SUCCESS
--------------------------------------------------------------------------------

 INFO [main] - Total time: 4.653 seconds
 INFO [main] - Finished at: Wed, 5 Jul 2017 18:06:46
 INFO [main] - Final memory: 181 M/ 266 M
 INFO [main] - Total modified files: 0
--------------------------------------------------------------------------------

Analysis - As it has Failed to load class "org.slf4j.impl.StaticLoggerBinder", so it is evident some jar is missing in the classpath. Now, question is which jar it expects to be downloaded ? I can check the console in details to see if that jar is downloaded and if not then how to add that jar file in the ivy list to be included ?

rpau commented 7 years ago

This fix is focused on remove unused variables, not field. So, the example is not appropriate.

subisueno commented 7 years ago

It is correctly working for local variables (Method scoped).