- final SchemaNode dataNode;
- if (xpath.isAbsolute()) {
- dataNode = findDataSchemaNode(schemaContext, module, xpath);
- } else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
- }
- Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
- strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule());
-
- if (leafContainsEnumDefinition(dataNode)) {
- returnType = referencedTypes.get(dataNode.getPath());
- } else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
- } else {
- returnType = resolveTypeFromDataSchemaNode(dataNode);
- }
- } else {
- returnType = Types.typeForClass(Object.class);
+ final SchemaNode dataNode;
+ if (xpath.isAbsolute()) {
+ dataNode = findDataTreeSchemaNode(schemaContext, module.getQNameModule(), xpath);
+ } else {
+ dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+ if (dataNode == null && inGrouping) {
+ // Relative path within a grouping may end up being unresolvable because it may refer outside
+ // the grouping, in which case it is polymorphic based on instantiation, for example:
+ //
+ // grouping foo {
+ // leaf foo {
+ // type leafref {
+ // path "../../bar";
+ // }
+ // }
+ // }
+ //
+ // container one {
+ // leaf bar {
+ // type string;
+ // }
+ // uses foo;
+ // }
+ //
+ // container two {
+ // leaf bar {
+ // type uint16;
+ // }
+ // uses foo;
+ // }
+ LOG.debug("Leafref type {} not found in parent {}, assuming polymorphic object", leafrefType,
+ parentNode);
+ return Types.objectType();