ModeShape/modeshape — pull request #274 by rhauch (2012-01-18 20:05:59+00:00)
Title: MODE-1374 Corrected node type init errors in concurrent environment

The JcrNodeDefinition is intended to be immutable and thread-safe, and although it is publicly immutable, internally it delays loading the references to the required primary types until needed. The `ensureRequiredPrimaryTypesLoaded()` method lazily initializes the references, and this method is properly called in the right spots within JcrNodeDefinition. However, in a highly-concurrent environment a node type definition may be needed by multiple threads, and this can result in this method being called concurrently. Unfortunately this method is not thread-safe, and can cause a NullPointerException when used concurrently.

Unlike the fix in the 2.x codebase, the fix for 3.x simply removes the cached JcrNodeType references (both the array and the map keyed by Name) from JcrNodeDefinition. This simplifies the JcrNodeDefinition class by making it fully immutable (not just publicly immutable), and it also ensures that when node types are updated, they are accurately reflected in all child node definitions.

With this change, all unit and integration tests pass.