Trait/Object

org.opalj.fpcf.properties

ObjectImmutability

Related Docs: object ObjectImmutability | package properties

Permalink

sealed trait ObjectImmutability extends OrderedProperty with ObjectImmutabilityPropertyMetaInformation

Specifies the mutability of instances of a specific class. The highest rating is "Immutable", then "Conditionally Immutable", then "Mutable".

An instance of a class is rated as immutable if the state of does not change after initialization in a client visible manner! This includes all classes referenced by the instances (transitive hull). However, fields that are lazily initialized (in a thread-safe manner) and which don't change after that do not impede immutability. Conditionally immutable means that the state of the instance of the respective class cannot be mutated, but objects referenced by it can be mutated (so called immutable collections are typically rated as "conditionally immutable"). Mutable means that a client can mutate (directly or indirectly) the state of respective objects. In general the state of a class is determined w.r.t. the declared fields. I.e., an impure method which has, e.g., a call time dependent behavior because it uses the current time, but which does not mutate the state of the class does not affect the mutability rating. The same is true for methods with side-effects related to the state of other types of object.

The mutability assessment is by default done on a per class basis and only directly depends on the super class of the analyzed class. A rating that is based on all actual usages is only meaningful if we analyze an application. E.g., imagine a simple mutable data container class where no field – in the concrete context of a specific application – is ever updated.

Thread-safe Lazily Initialized Fields

A field that is initialized lazily in a thread-safe manner; i.e., which is set at most once after construction and which is always set to the same value independent of the time of (lazy) initialization, may not affect the mutability rating. However, an analysis may rate such a class as mutable. An example of such a field is the field that stores the lazily calculated hashCode of a String object.

Inheritance

Native Methods

Unknown native methods are considered as mutating the state unless all state is explicitly final; however, this is already handled by the org.opalj.fpcf.analysis.FieldMutabilityAnalysis.

Identifying Immutable Objects in Practice

Identifying real world immutable classes as such by means of an analysis is in general a challenging task. For example, to identify the well known immutable class "java.lang.String" as such requires:

Interfaces

Are not considered during the analysis as they are always immutable. (All fields are (implicitly) static and final.)

Linear Supertypes
ObjectImmutabilityPropertyMetaInformation, OrderedProperty, Property, PropertyMetaInformation, PropertyKind, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ObjectImmutability
  2. ObjectImmutabilityPropertyMetaInformation
  3. OrderedProperty
  4. Property
  5. PropertyMetaInformation
  6. PropertyKind
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final type Self = ObjectImmutability

    Permalink
    Definition Classes
    ObjectImmutabilityPropertyMetaInformation → PropertyMetaInformation

Abstract Value Members

  1. abstract def correspondingTypeImmutability: TypeImmutability

    Permalink
  2. abstract def isMutable: Answer

    Permalink
  3. abstract def isRefineable: Boolean

    Permalink
    Definition Classes
    Property
  4. abstract def isValidSuccessorOf(other: OrderedProperty): Option[String]

    Permalink
    Definition Classes
    OrderedProperty

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. final def asOrderedProperty: ObjectImmutability.this.type

    Permalink
    Definition Classes
    OrderedProperty → Property
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def id: Int

    Permalink
    Definition Classes
    PropertyMetaInformation → PropertyKind
  13. final def isFinal: Boolean

    Permalink
    Definition Classes
    Property
  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. final def isOrdered: Boolean

    Permalink
    Definition Classes
    OrderedProperty → Property
  16. final def key: PropertyKey[ObjectImmutability]

    Permalink

    Returns the key used by all ObjectImmutability properties.

    Returns the key used by all ObjectImmutability properties.

    Definition Classes
    ObjectImmutability → PropertyMetaInformation
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from OrderedProperty

Inherited from Property

Inherited from PropertyMetaInformation

Inherited from PropertyKind

Inherited from AnyRef

Inherited from Any

Ungrouped