GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Error Prone
  • Bug Patterns
  • Docs
  • GitHub

This view

  • Original page
  • New address

GeezerVison is showing errorprone.info — ArrayRecordComponent

ArrayRecordComponent
Record components should not be arrays.

Severity
WARNING

The problem

There are two main problems with having a component of a record be an array.

  1. By default, the generated equals and hashCode will just call equals or hashCode on the array. Two distinct arrays are never considered equal by equals even if their contents are the same. The generated toString is similarly not useful, since it will be something like [B@723279cf.

  2. Arrays are mutable, but records should not be mutable. A client of a record with an array component can change the contents of the array.

Instead of an array component, consider something like ImmutableList<String>, or, for primitive arrays, something like ByteString or ImmutableIntArray.

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ArrayRecordComponent") to the enclosing element.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.