6 Replies Latest reply on Sep 24, 2007 3:38 PM by Ales Justin

    Problem deploying bean with a property annotation

    Scott Stark Master

      If I deploy a bean like:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns="urn:jboss:bean-deployer:2.0">
       <bean name="AnnotatedBean" class="org.jboss.test.deployers.vfs.deployer.bean.support.AnnotatedBean">
       <annotation>@org.jboss.managed.api.annotation.ManagementComponent(type="MCBean",subtype="AnnotationTest")</annotation>
       <!-- Test -->
       <property name="propWithXmlOverride">
       <annotation>@org.jboss.managed.api.annotation.ManagementProperty(name="prop3", mappedName="propWithXmlOverride", description="ManagedProperty defined via xml annotation")</annotation>
       </property>
       </bean>
      


      I see:

      17610 ERROR [AbstractKernelController] Error installing to Configured: name=AnnotatedBean state=Instantiated
      java.lang.IllegalArgumentException: Null value metadata
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoint(Configurator.java:497)
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoint(Configurator.java:444)
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoints(Configurator.java:408)
      at org.jboss.kernel.plugins.config.AbstractKernelConfigurator.getPropertySetterJoinPoints(AbstractKernelConfigurator.java:120)
      at org.jboss.kernel.plugins.dependency.ConfigureAction.installActionInternal(ConfigureAction.java:59)
      at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:137)
      at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:1)
      at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
      at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
      at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
      at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
      at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:574)
      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:398)
      at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:68)
      at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:1)
      at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.deploy(AbstractSimpleRealDeployer.java:65)
      at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
      at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:728)
      at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:749)
      at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:669)
      at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
      at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
      at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:495)
      at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:354)
      at org.jboss.test.deployers.vfs.deployer.jaxp.DeployerClientTestCase.assertDeploy(DeployerClientTestCase.java:57)
      at org.jboss.test.deployers.vfs.deployer.jaxp.DeployerClientTestCase.assertDeploy(DeployerClientTestCase.java:46)
      at org.jboss.test.deployers.vfs.deployer.bean.test.BeanManagedDeploymentUnitTestCase.testBeanManagedObject(BeanManagedDeploymentUnitTestCase.java:59)


      If I add a value with any whitespace I see:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns="urn:jboss:bean-deployer:2.0">
       <bean name="AnnotatedBean" class="org.jboss.test.deployers.vfs.deployer.bean.support.AnnotatedBean">
       <annotation>@org.jboss.managed.api.annotation.ManagementComponent(type="MCBean",subtype="AnnotationTest")</annotation>
       <!-- Test -->
       <property name="propWithXmlOverride">
       <annotation>@org.jboss.managed.api.annotation.ManagementProperty(name="prop3", mappedName="propWithXmlOverride", description="ManagedProperty defined via xml annotation")</annotation>
       10
       </property>
       </bean>
      


      I see:

      1969 ERROR [AbstractKernelController] Error installing to Configured: name=AnnotatedBean state=Instantiated
      java.lang.NumberFormatException: For input string: "
      10"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Integer.parseInt(Integer.java:447)
      at java.lang.Integer.valueOf(Integer.java:553)
      at sun.beans.editors.IntEditor.setAsText(IntEditor.java:21)
      at org.jboss.reflect.plugins.ValueConvertor.convertValue(ValueConvertor.java:120)
      at org.jboss.reflect.spi.PrimitiveInfo.convertValue(PrimitiveInfo.java:169)
      at org.jboss.beans.metadata.plugins.StringValueMetaData.getValue(StringValueMetaData.java:101)
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoint(Configurator.java:500)
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoint(Configurator.java:444)
      at org.jboss.kernel.plugins.config.Configurator.getPropertySetterJoinPoints(Configurator.java:408)
      at org.jboss.kernel.plugins.config.AbstractKernelConfigurator.getPropertySetterJoinPoints(AbstractKernelConfigurator.java:120)
      at org.jboss.kernel.plugins.dependency.ConfigureAction.installActionInternal(ConfigureAction.java:59)
      at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:137)
      at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:1)
      at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)



      If the property value is given with no whitespace it deploys correctly. We should be able to specify a property with just an annotation. In terms of the whitespace behavior, I would say the StringValueMetaData should also have a trim property that is also true by default.


        • 1. Re: Problem deploying bean with a property annotation
          Ales Justin Master

          OK, I'll add the trim attribute.
          Will see what we can do with a property w/o any value.

          • 2. Re: Problem deploying bean with a property annotation
            Ales Justin Master

            Should I add a new method on TypeInfo for applying this trim, as we did with sys property replace:

             /**
             * Convert a value
             *
             * @param value the original value
             * @param replaceProperties whether to replace properties
             * @return the converted value
             * @throws Throwable for any error
             */
             Object convertValue(Object value, boolean replaceProperties) throws Throwable;
            
             /**
             * Convert a value
             *
             * @param value the original value
             * @param replaceProperties whether to replace properties
             * @param trim do we trim
             * @return the converted value
             * @throws Throwable for any error
             */
             Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable;
            
            


            So that this trim is not just a setting of StringValueMetaData.

            • 3. Re: Problem deploying bean with a property annotation
              Ales Justin Master

              OK, I added this piece to TypeInfo --> ValueConvertor.
              You can now set trim=false on property or parameter.

              • 4. Re: Problem deploying bean with a property annotation
                Ales Justin Master

                 

                "alesj" wrote:

                Will see what we can do with a property w/o any value.

                What should be a proper handling of this?

                This is where is all starts:
                ConfigureAction --> Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);

                Configurator:
                 public static Set<TargettedJoinpoint> getPropertySetterJoinPoints(BeanInfo info, BeanMetaData metaData) throws Throwable
                 {
                 boolean trace = log.isTraceEnabled();
                
                 if (info == null)
                 throw new IllegalArgumentException("Null bean info");
                 if (metaData == null)
                 throw new IllegalArgumentException("Null bean metadata");
                
                 Set<TargettedJoinpoint> result = new HashSet<TargettedJoinpoint>();
                 Set<PropertyMetaData> propertys = metaData.getProperties();
                 if (propertys != null && propertys.isEmpty() == false)
                 {
                 ClassLoader cl = getClassLoader(metaData);
                
                 for (Iterator i = metaData.getProperties().iterator(); i.hasNext();)
                 {
                 PropertyMetaData property = (PropertyMetaData) i.next();
                 // PERHAPS ADD CONDITION HERE - if non null value meta data on property?
                 TargettedJoinpoint joinPoint = getPropertySetterJoinPoint(trace, info, cl, property);
                 result.add(joinPoint);
                 }
                 }
                
                 return result;
                 }
                


                • 5. Re: Problem deploying bean with a property annotation
                  Scott Stark Master

                  The mixed content type on the property element makes this a little difficult to determine whether a property value was set. If there is no ValueMetaData though, there is no reason to call the setter.

                  • 6. Re: Problem deploying bean with a property annotation
                    Ales Justin Master

                     

                    "scott.stark@jboss.org" wrote:
                    The mixed content type on the property element makes this a little difficult to determine whether a property value was set. If there is no ValueMetaData though, there is no reason to call the setter.

                    I agree.
                    But I don't think that should be Configurators responsibility, to distinguish between properties for annotations sake or those real one's with value.

                    But on the other hand, I currently don't see any other way ...
                    Perhaps making it optional, to have a strict behavior, or by setting a flag to ease up the value requirement.