Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
The code below currently leads to a NPE in registerNodeType() due to the missing name of the wildcard node definition. Uncommenting the setName() call fixes the issue.
NodeTypeManager manager = ...;
NodeTypeTemplate type = manager.createNodeTypeTemplate();
NodeDefinitionTemplate wildcard = manager.createNodeDefinitionTemplate();
// wildcard.setName("*");
type.getNodeDefinitionTemplates().add(wildcard);
manager.registerNodeType(type, false);
Whatever we do, the code should not throw a NullPointerException. There are basically two valid approaches:
1) Throw an exception in registerNodeType() if the name of an item definition has not been specified.
2) Treat item definitions with unspecified names as residual.
Note that a ItemDefinition.getName() is explicitly specified to return null (instead of "*") when the name has not been set, which seems to suggest that option 1 above is the correct behaviour. On the other hand, the respective setName() call is specified to accept only a "syntactically valid JCR name", which would suggest option 2 as the correct alternative.
Personally I tend to like option 2 better, as that's also how I intuitively was using the API when I ran into the NPE error. That approach was also what Jackrabbit used to do before the node type handling was recently merged with the SPI code.