Skip to content

Resolve violations from IDEA 2018.1.6 #6037

@romani

Description

@romani

Download latest IDEA Community edition 2018.1.6
Run inspections from IDEA.

Following violations appear:

Inheritance issues
Abstract class without abstract methods

File:
AbstractXpathTestSupport

Message:
Class 'AbstractXpathTestSupport' is declared 'abstract', and has no 'abstract' methods

TODO:
this should not be abstract, need to be fixed.

Nuance (probably is reason why it become Abstract):
If we fix we run into checkstyle violation -
[checkstyle] [ERROR] src/it/java/org/checkstyle/suppressionxpathfilter/XpathTestSupport.java:0: File not match folder pattern '[\\/]src[\\/]it[\\/]java[\\/]' and file pattern '^((\w+Test)|(Abstract\w+))\.java$'. [RegexpOnFilename]

===============

J2ME issues - Abstract class which has only one direct inheritor
Abstract class 'XXXXXXX' has only one direct inheritor

Files:
AbstractIndentationTestSupport
AbstractPathTestSupport

IDEA description:
This inspection is intended for J2ME and other highly resource constrained environments. Applying the results of this inspection without consideration might have negative effects on code clarity and design.
Reports abstract classes which have precisely one direct inheritor. While such classes may offer admirable clarity of design, in memory-constrained or bandwidth-limited environments, they needlessly increase the total footprint of the application. Consider merging the abstract class with its inheritor.

TODO: we need to suppress this inspection with note:
"we are not limited in resources and we a library so there are more usages outside of our code"

=========================

Javadoc - Declaration has problems in Javadoc references

file:
AbstractModuleTestSupport

Messages:
Cannot resolve symbol 'getConfiguration()'
Cannot resolve symbol 'getConfiguration()'
Cannot resolve symbol 'getConfiguration()'

TODO:
just fix such problems

=========================

Performance - 'Collection.toArray()' call style

Message: Call to 'toArray()' with pre-sized array argument 'new Integer[result.size()]'

Files:
AbstractIndentationTestSupport
AbstractModuleTestSupport

Description:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).
In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.
This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).

After a fix there is violation from another inspection

"Memory - Zero-length array allocation"

Decription:
Reports on allocations of arrays with known lengths of zero. Since array lengths in Java are non-modifiable, it is almost always possible to share zero-length arrays, rather than repeatedly allocating new zero-length arrays. Such sharing may provide useful optimizations in program runtime or footprint. Note that this inspection does not report zero-length arrays allocated as static final fields, as it is assumed that those arrays are being used to implement array sharing.

Lets suppress "Zero-length array allocation" completely with note:
"conficting with "

========================

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions