NanoContainer
  1. NanoContainer
  2. NANO-89

testSoftInstantiateWithChildContainerWithDynamicClassPath() fails for reasons of inaccessible Groovy attributes

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-RC1
    • Component/s: groovy
    • Labels:
      None
    • Number of attachments :
      0

      Description

      See
      NanoGroovyBuilderTestCase.groovy
      testSoftInstantiateWithChildContainerWithDynamicClassPath()

      This must be ficed before NanoContainer ships.

        Activity

        Paul Hammant made changes -
        Field Original Value New Value
        Description See
        NanoGroovyBuilderTestCase.groovy
          testSoftInstantiateWithChildContainer()

        This must be ficed before NanoContainer ships.
        See
        NanoGroovyBuilderTestCase.groovy
          testSoftInstantiateWithChildContainerWithDynamicClassPath()

        This must be ficed before NanoContainer ships.
        Summary testSoftInstantiateWithChildContainer fails for reasons of inaccessible Groovy attributes testSoftInstantiateWithChildContainerWithDynamicClassPath() fails for reasons of inaccessible Groovy attributes
        Hide
        Kouhei Mori added a comment -

        NullPointerException (attributes.remove("path") returns null) is resolved by createClassPathElementNode returns something non-null object. For example:

        Index: src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java
        ===================================================================
        RCS file: /scm/picocontainer/java/nanocontainer/src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java,v
        retrieving revision 1.6
        diff -u -r1.6 NanoGroovyBuilder.java
        — src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 25 Jun 2004 13:40:15 -0000 1.6
        +++ src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 26 Jun 2004 08:25:54 -0000
        @@ -102,7 +102,7 @@
        throw new PicoBuilderException("classpath '" + path + "' malformed ", e);
        }
        reflectionContainerAdapter.addClassLoaderURL(pathURL);

        • return null;
          + return pathURL;
          }

        private Object createBeanNode(Map attributes, MutablePicoContainer pico) {

        This is because when createNode returns null, BuilderSupport line 140-142 calls createNode once more.

        But, there is another failure:

        Testcase: testSoftInstantiateWithChildContainerWithDynamicClassPath(org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase): Caused an ERROR
        Must specify a class attribute for a component
        org.nanocontainer.script.groovy.PicoBuilderException: Must specify a class attribute for a component
        at org.nanocontainer.script.groovy.NanoGroovyBuilder.createComponentNode(NanoGroovyBuilder.java:126)
        at org.nanocontainer.script.groovy.NanoGroovyBuilder.createChildOfContainerNode(NanoGroovyBuilder.java:72)
        at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:64)
        at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:47)
        at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:56)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:107)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85)
        at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
        at groovy.lang.Closure.invokeMethod(Closure.java:135)
        at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
        at org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase$_testSoftInstantiateWithChildContainerWithDynamicClassPath_closure5.doCall(/usr/home/ko-hey/cvswork/picocontainer/nanocontainer/target/test-classes/org/nanocontainer/script/groovy/NanoGroovyBuilderTestCase.groovy:142)
        at groovy.lang.Closure.call(Closure.java:280)
        at groovy.lang.Closure.call(Closure.java:212)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:155)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85)
        at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
        at org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase.testSoftInstantiateWithChildContainerWithDynamicClassPath(/usr/home/ko-hey/cvswork/picocontainer/nanocontainer/target/test-classes/org/nanocontainer/script/groovy/NanoGroovyBuilderTestCase.groovy:140)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        Show
        Kouhei Mori added a comment - NullPointerException (attributes.remove("path") returns null) is resolved by createClassPathElementNode returns something non-null object. For example: Index: src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java =================================================================== RCS file: /scm/picocontainer/java/nanocontainer/src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java,v retrieving revision 1.6 diff -u -r1.6 NanoGroovyBuilder.java — src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 25 Jun 2004 13:40:15 -0000 1.6 +++ src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 26 Jun 2004 08:25:54 -0000 @@ -102,7 +102,7 @@ throw new PicoBuilderException("classpath '" + path + "' malformed ", e); } reflectionContainerAdapter.addClassLoaderURL(pathURL); return null; + return pathURL; } private Object createBeanNode(Map attributes, MutablePicoContainer pico) { This is because when createNode returns null, BuilderSupport line 140-142 calls createNode once more. But, there is another failure: Testcase: testSoftInstantiateWithChildContainerWithDynamicClassPath(org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase): Caused an ERROR Must specify a class attribute for a component org.nanocontainer.script.groovy.PicoBuilderException: Must specify a class attribute for a component at org.nanocontainer.script.groovy.NanoGroovyBuilder.createComponentNode(NanoGroovyBuilder.java:126) at org.nanocontainer.script.groovy.NanoGroovyBuilder.createChildOfContainerNode(NanoGroovyBuilder.java:72) at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:64) at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:47) at org.nanocontainer.script.groovy.NanoGroovyBuilder.createNode(NanoGroovyBuilder.java:56) at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:107) at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85) at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106) at groovy.lang.Closure.invokeMethod(Closure.java:135) at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106) at org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase$_testSoftInstantiateWithChildContainerWithDynamicClassPath_closure5.doCall(/usr/home/ko-hey/cvswork/picocontainer/nanocontainer/target/test-classes/org/nanocontainer/script/groovy/NanoGroovyBuilderTestCase.groovy:142) at groovy.lang.Closure.call(Closure.java:280) at groovy.lang.Closure.call(Closure.java:212) at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:155) at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:85) at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:128) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106) at org.nanocontainer.script.groovy.NanoGroovyBuilderTestCase.testSoftInstantiateWithChildContainerWithDynamicClassPath(/usr/home/ko-hey/cvswork/picocontainer/nanocontainer/target/test-classes/org/nanocontainer/script/groovy/NanoGroovyBuilderTestCase.groovy:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        Hide
        Paul Hammant added a comment -

        Good work. I think I may have changed the underlying code with recent changes - though the bug is still there

        • paul
        Show
        Paul Hammant added a comment - Good work. I think I may have changed the underlying code with recent changes - though the bug is still there paul
        Hide
        Paul Hammant added a comment -

        container nesting now works. sort of at least.

        Untested is the getParent() elements of classloaders that are created behind the scenes and getting of components out of the containers by key

        Show
        Paul Hammant added a comment - container nesting now works. sort of at least. Untested is the getParent() elements of classloaders that are created behind the scenes and getting of components out of the containers by key
        Hide
        Kouhei Mori added a comment -

        Index: src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java
        ===================================================================
        RCS file: /scm/picocontainer/java/nanocontainer/src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java,v
        retrieving revision 1.9
        diff -u -r1.9 NanoGroovyBuilder.java
        — src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 1 Jul 2004 07:03:27 -0000 1.9
        +++ src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 2 Jul 2004 05:44:13 -0000
        @@ -48,7 +48,7 @@
        }

        protected Object createNode(Object name, Object value) {

        • if (value instanceof Class) {
          + if (value instanceof Class || value instanceof String) {
          Map attributes = new HashMap();
          attributes.put("class", value);
          return createNode(name, attributes);

        also enables

        component("TestComp")

        style component composition.

        Show
        Kouhei Mori added a comment - Index: src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java =================================================================== RCS file: /scm/picocontainer/java/nanocontainer/src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java,v retrieving revision 1.9 diff -u -r1.9 NanoGroovyBuilder.java — src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 1 Jul 2004 07:03:27 -0000 1.9 +++ src/java/org/nanocontainer/script/groovy/NanoGroovyBuilder.java 2 Jul 2004 05:44:13 -0000 @@ -48,7 +48,7 @@ } protected Object createNode(Object name, Object value) { if (value instanceof Class) { + if (value instanceof Class || value instanceof String) { Map attributes = new HashMap(); attributes.put("class", value); return createNode(name, attributes); also enables component("TestComp") style component composition.
        Hide
        Stephen Molitor added a comment -

        The reason this test fails (when line 145 is uncommented) is because TestComp2 is registered with the class as the component key, but retrieved using a String as the key. The component is registered on line 140 as follows:

        component(class:"TestComp2")

        The container using reflection to look up the class, and registers the component under the key TestComp2.class. But line 145 tries to look it up using a String:

        assertNotNull(child.getComponentInstance("TestComp2"))

        If line 140 is changed to this:

        component(key:"TestComp2", class:"TestComp2")

        then the test will work. Alternately the assertion could be changed to look up the component using the class as the key.

        Show
        Stephen Molitor added a comment - The reason this test fails (when line 145 is uncommented) is because TestComp2 is registered with the class as the component key, but retrieved using a String as the key. The component is registered on line 140 as follows: component(class:"TestComp2") The container using reflection to look up the class, and registers the component under the key TestComp2.class. But line 145 tries to look it up using a String: assertNotNull(child.getComponentInstance("TestComp2")) If line 140 is changed to this: component(key:"TestComp2", class:"TestComp2") then the test will work. Alternately the assertion could be changed to look up the component using the class as the key.
        Mauro Talevi made changes -
        Environment
        Component/s groovy [ 11631 ]
        Description See
        NanoGroovyBuilderTestCase.groovy
          testSoftInstantiateWithChildContainerWithDynamicClassPath()

        This must be ficed before NanoContainer ships.
        See
        NanoGroovyBuilderTestCase.groovy
          testSoftInstantiateWithChildContainerWithDynamicClassPath()

        This must be ficed before NanoContainer ships.
        Hide
        Mauro Talevi added a comment -

        Fixed in 1.0-RC1

        Show
        Mauro Talevi added a comment - Fixed in 1.0-RC1
        Mauro Talevi made changes -
        Fix Version/s 1.0-RC1 [ 11850 ]
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 1.0 [ 10148 ]
        Resolution Fixed [ 1 ]
        Hide
        Paul Hammant added a comment -

        I've also added recently a classKey:"Foo" attribute to component(). Just FYI

        Show
        Paul Hammant added a comment - I've also added recently a classKey:"Foo" attribute to component(). Just FYI

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul Hammant
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: