cqfn / aibolit

Static Analyzer for Java Code with Machine Learning in Mind
https://pypi.org/project/aibolit/
51 stars 17 forks source link

Bug with P21 (var in the middle) #596

Open KatGarmash opened 4 years ago

KatGarmash commented 4 years ago

Aibolit detects P21 in lines 6,7,8, but it should not, since becase the only preceding expression in super invocation.

   1             Group(String objectNameBase, List<String> objectNames,
   2                             List<? extends PlatformManagedObject> implementations,
   3                             Set<Class<?>> interfaceTypes) {
   4                     super(objectNameBase.concat(",name=*"), interfaceTypes); //$NON-NLS-1$
   5
   6                     int beanCount = implementations.size();
   7                    Map<String, Object> beanMap = new HashMap<>(beanCount);
   8                     String namePrefix = objectNameBase.concat(",name="); //$NON-NLS-1$
   9
   10                     for (int i = 0; i < beanCount; ++i) {
....
KatGarmash commented 4 years ago

Also, it detects the P21 here:

 private static final class Group extends Component {

                private final Map<String, Object> nameToMBeanMap;

                Group(String objectNameBase, List<String> objectNames,
                                List<? extends PlatformManagedObject> implementations,
                                Set<Class<?>> interfaceTypes) {

                        int beanCount = implementations.size();
                        Map<String, Object> beanMap = new HashMap<>(beanCount);
                        String namePrefix = objectNameBase.concat(",name="); //$NON-NLS-1$

                        for (int i = 0; i < beanCount; ++i) {
                                String objectName = namePrefix.concat(objectNames.get(i));
                                PlatformManagedObject implementation = implementations.get(i);

                                beanMap.put(objectName, implementation);
                        }