Immutizer4J: library for validating immutability of Java object graphs

Immutizer4J: library for validating immutability of Java object graphs

The lack of built-in support for immutability in Java can be an issue when caching complex object graphs within large in-memory caches or when passing objects as messages between threads (in actor oriented frameworks such as Akka or Lois).

The simple "final" keyword is insufficient, as the type itself it refers may be mutable. Or may a final collection stores elements that are mutable themselves, etc.

Immutizer4J is a small library I wrote that helps to avoid these types of issues by validating the entire object graph:

https://github.com/jacek99/immutizer4j

It offers the following functionality:

  • walks down the entire object graph
  • ensures all fields in every type are final
  • ensures only immutable collections are used
  • ensures only immutable types are stored within collections (yes, it works around generics type erasure)

This is an initial release, so feel free to check it out, provide feedback, submit ideas for improvements, etc.

To view or add a comment, sign in

More articles by Jacek Furmankiewicz

Explore content categories