sevntu-checkstyle / sevntu.checkstyle

Additional Checkstyle checks, that could be added as extension to EclipseCS plugin and maven-checkstyle-plugin, Sonar checkstyle plugin, extension for CheckStyle IDEA plugin.
http://sevntu-checkstyle.github.io/sevntu.checkstyle/
190 stars 146 forks source link

DiamondOperatorForVariableDefinitionCheck false negatives #458

Open romani opened 8 years ago

romani commented 8 years ago

Force Diamond check missed following cases: https://github.com/checkstyle/checkstyle/commit/1395a92adb0d8fd0767bee81dc407c5e58b37252

Check: https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/DiamondOperatorForVariableDefinitionCheck.java

scop commented 8 years ago

Not sure if it's the same issue, but it also misses cases like:

HashMap<String, String> foo;
foo = new HashMap<String, String>();
rnveach commented 7 years ago

Current check is only looking at VARIABLE_DEF and it looks like it needs to look at LITERAL_NEW too. It probably should follow variable declarations and scope similar to RequireThisCheck.

One issue with:

-        this(new HashMap<String, String>(1));
+        this(new HashMap<>(1));

We can't tell if the method parameter is missing type or has wildcard type. This may be a limitation of the check if method/constructor is declared in another file.

romani commented 7 years ago

This may be a limitation of the check

this is limitation of the whole checkstyle. Check should skip such cases from validation.