Affects Sonarqube Version:
Sonarqube version: 8.1.0.31237
sonar-scanner version: 4.2.0.1873-windows
Rule:
S2133: Objects should not be created only to “getClass”
Description:
Unable to detect getClass called by array of classes,such as: new Object[0].getClass()
This rule is implemented in java-checks-6.2.0.21135-sources.jar!\org\sonar\java\checks\ObjectCreatedOnlyToCallGetClassCheck.java.
This rule uses TypeCriteria.subtypeOf(“java.lang.Object”)).name(“getClass”).withoutParameter()
to filter class objects that may have errors, but the array of class objects may be ignored.
Code Sample demonstrating the issue:
assertEquals(new Long[0].getClass(), types[0]);
Constructor<?> constructor = nsDataClass.getConstructor(new Class[]{new byte[0].getClass()});
Expected outcome:
false-negative
Running Sonarqube through:
command line