Unnecessary zero length array usage
Reports allocations of arrays with known lengths of zero when there is a constant for that in the class of the array's element type. As zero-length arrays are immutable, you can save memory reusing the same array instance.
Example:
class Item {
// Public zero-length array constant that can be reused
public static final Item[] EMPTY_ARRAY = new Item[0];
}
class EmptyNode {
Item[] getChildren() {
// Unnecessary zero-length array creation
return new Item[0];
}
}After the quick-fix is applied:
class EmptyNode {
Item[] getChildren() {
return Item.EMPTY_ARRAY;
}
}- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
ConstantForZeroLengthArrayAllocation
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
//noinspection ConstantForZeroLengthArrayAllocationnote
Actual comment syntax will depend on the code language you are working with
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |