# Unexpected behavior using a custom extension with a NamedDomainObjectContainer

**URL:** <https://discuss.gradle.org/t/unexpected-behavior-using-a-custom-extension-with-a-nameddomainobjectcontainer/21227>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [January 19, 2017, 2:10pm UTC](https://discuss.gradle.org/t/unexpected-behavior-using-a-custom-extension-with-a-nameddomainobjectcontainer/21227 "2017-01-19T14:10:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glward](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/glward/32/5868_2.png) [@glward](https://discuss.gradle.org/u/glward)\
**Post date:** [January 19, 2017, 2:10pm UTC](https://discuss.gradle.org/t/unexpected-behavior-using-a-custom-extension-with-a-nameddomainobjectcontainer/21227/1 "2017-01-19T14:10:31Z")

</div>

I’ve created a plugin that has a set of nested extensions, using a NamedDomainObjectContainer on the parent extension to hold the child extensions, like so:

```
class TestExtension {
  final NamedDomainObjectContainer<NestedExtension> data
 
  public TestExtension(Project project) {
    data = project.container(NestedExtension)
  }

  public data(Closure config) {
    this.data.configure(config)
  }
}

```

Where “NestedExtension” is just:

```
@Canonical
class NestedExtension {
  final String name
  String data
}

```

However, using a String literal as the name without a configuration closure does not allow the object to be created. Using the following example, only “foo” and “foo bar baz” are created.

```
test {
    data {
        foo
        "bar"
        "bar baz"
        "foo bar baz" {}
    }
}

```

I’ve tested this in 2.14.1 and 3.3 and it presents in both places. I’m not sure if this is a bug or just a misunderstanding on my part of how the named objects are created when a NamedDomainObjectContainer is configured–figured I’d ask here first to see if there’s something silly I’m doing.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [January 20, 2017, 5:02am UTC](https://discuss.gradle.org/t/unexpected-behavior-using-a-custom-extension-with-a-nameddomainobjectcontainer/21227/2 "2017-01-20T05:02:20Z")

</div>

I think this is because Groovy is just treating “bar” like a literal expression. That is, there is no context here to indicate that you are attempting to reference an existing symbol or call a method. Doing “bar”() should give you the behavior you want.
