Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: SomeType is immutable

...

Noncompliant Code Example

Suppose that SomeType is immutable.

Code Block
bgColor#FFCCCC
public static final SomeType [] SOMETHINGS = { ... };

With this This declaration , SOMETHINGS[1], etc. can allows the SOMETHINGS array to be modified by untrusted clients of the code. Any element of the array can be assigned a new value.

This noncompliant code example also violates OBJ01-J. Limit accessibility of fields.

...

Code Block
bgColor#ccccff
private static final SomeType [] SOMETHINGS = { ... };
public static final SomeType [] somethings() {
  return SOMETHINGS.clone();
}

Now, the original array values cannot be modified by a any client.

Compliant Solution 2

...