You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by keinmensch <ke...@mailhaven.com> on 2009/12/14 14:32:59 UTC

Non-Simple Property Injected with XML Fails with NPE

Hi!
Another question regarding properties of components, this time about
properties that are not simple XSD types and that are injected with XML
data.
With a look at the property tests in the itest directory in the source
distribution, I tried this:
In the composite file (inside a component):
...
        <property name="person" element="ivan:person">
            <person xmlns="http://www.ivan.com/person">
                <firstName>DeeDee</firstName>
                <lastName>Ramone</lastName>
                <age>49</age>
            </person>
        </property>
    </component>
...

In the component implementation class; the field to be injected:
    @Property(name="person", required=false)
    protected Person mPerson;

Then I have a class Person which contains two string fields firstName,
lastName and one integer field age with corresponding getters and
setters. No annotations.

In the same directory as the composite, I have the following XML schema:
<?xml version="1.0" encoding="UTF-8"?>
<schema
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:ivan="http://www.ivan.com/person"
    targetNamespace="http://www.ivan.com/person"
    attributeFormDefault="unqualified">
   
    <element name="person" type="ivan:Person"/>
    <complexType name="Person">
        <sequence>
            <element name="firstName" type="string" nillable="false"/>
            <element name="lastName" type="string" nillable="false"/>
            <element name="age" type="int"/>
        </sequence>
    </complexType>
</schema>

Finally, when I run the program, I there is the following exception:
Exception in thread "main" java.lang.IllegalStateException:
org.apache.tuscany.sca.assembly.builder.CompositeBuilderException:
Exception while building model
{http://docs.oasis-open.org/ns/opencsa/sca/200903}
    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:176)
    at
com.ivan.client.SCAPropertyPrinterClient.main(SCAPropertyPrinterClient.java:27)
Caused by:
org.apache.tuscany.sca.assembly.builder.CompositeBuilderException:
Exception while building model
{http://docs.oasis-open.org/ns/opencsa/sca/200903}
    at
org.apache.tuscany.sca.builder.impl.ModelBuilderImpl.build(ModelBuilderImpl.java:140)
    at
org.apache.tuscany.sca.assembly.builder.DefaultBuilderExtensionPoint$LazyCompositeBuilder.build(DefaultBuilderExtensionPoint.java:224)
    at
org.apache.tuscany.sca.deployment.impl.DeployerImpl.build(DeployerImpl.java:449)
    at
org.apache.tuscany.sca.node.impl.NodeFactoryImpl.configureNode(NodeFactoryImpl.java:274)
    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:135)
    ... 1 more
Caused by: java.lang.NullPointerException
    at
org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl.reconcileComponentPropertyWithComponentType(ComponentBuilderImpl.java:649)
    at
org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl.configureProperties(ComponentBuilderImpl.java:329)
    at
org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl.configureComponentFromComponentType(ComponentBuilderImpl.java:142)
    at
org.apache.tuscany.sca.builder.impl.CompositeComponentTypeBuilderImpl.createComponentType(CompositeComponentTypeBuilderImpl.java:126)
    at
org.apache.tuscany.sca.builder.impl.ModelBuilderImpl.build(ModelBuilderImpl.java:111)
    ... 5 more

I have also tried the tests in the itest/properties, which I seriously
doubt that they ever have been able to pass given that there is no XML
schema defining the type/element used in the composite.
If anyone has any hints, I would be very grateful. Feel like I have
tried "everything", but I am sure there is something I overlooked.
Best regards!
 Ivan


Re: Non-Simple Property Injected with XML Fails with NPE

Posted by Brent Daniel <br...@gmail.com>.
Hi,
I think it's still a legitimate problem. Right now the XSDType of the
Property introspected from the java class will always be null (unless
it's a simple type.) I think the introspection code should probably be
checking for JAXB annotations on the class and getting the appropriate
XSDType from there.. ie, something like this in
AbstractPropertyProcessor.createProperty()...

 property.setXSDType(JavaXMLMapper.getXMLType(baseType));

        if ( property.getXSDType() == null ) {
        	XmlType cl = baseType.getAnnotation(XmlType.class);
        	if ( cl != null ) {
        		property.setXSDType(new QName(cl.namespace(), cl.name()));
        	}
        }

In the case where the xsd type can't be inferred at all, it makes
sense to me to make the check less restrictive.

Brent


On Fri, Jan 15, 2010 at 4:58 PM, keinmensch <ke...@mailhaven.com> wrote:
> Hi!
> Yes, I opened a Jira, TUSCANY-3409, but also closed it, since it looked
> like the unit test that was failing here was successfull when run by Hudson.
> I assumed that my environment or something caused the issue. I still
> haven't managed to solve, or workaround, the problem, by the way.
> Best wishes!
>

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by keinmensch <ke...@mailhaven.com>.
Hi!
Yes, I opened a Jira, TUSCANY-3409, but also closed it, since it looked
like the unit test that was failing here was successfull when run by Hudson.
I assumed that my environment or something caused the issue. I still
haven't managed to solve, or workaround, the problem, by the way.
Best wishes!

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by Brent Daniel <br...@gmail.com>.
Was a JIRA ever opened for this? I just ran into the same problem
trying to run a similar complexType property test case on 2.x.

Brent

On Sun, Jan 3, 2010 at 6:19 AM, keinmensch <ke...@mailhaven.com> wrote:
> keinmensch wrote:
>> ant elder wrote:
>>
>>> Hi Ivan, could you raise a JIRA for this and if possible attach to it
>>> the sca contribution you're trying to get to work, and I or someone
>>> else will try to get it fixed for you.
>>>
>>
>> Hi!
>> Many thanks!
>> I did try to look into the problem myself, but after four hours, I just
>> felt like I had been walking around in circles. :-P
>> I have prepared a unit test and will create a JIRA as soon as I have a
>> little more time (later next week, I guess).
>> Note that this issue is in no way critical to me and I am not in a hurry.
>> Best wishes!
>>  Ivan
>>
>>
> Hello again!
> After some more digging, I have found that there is already a unit test
> that fails with a NullPointerException during circumstances that seems
> indentical to those I have experienced.
> So, before creatinga JIRA entry, I want to check with others to make
> sure that this is not an isolated issue I am experiencing.
> The unit test in question is:
> Package: org.apache.tuscany.sca.deployment.impl
> Class: DeployerImplTestCase
> Method: testBuild
>
> Thanks and best wishes!
>  Ivan
>

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by keinmensch <ke...@mailhaven.com>.
keinmensch wrote:
> ant elder wrote:
>   
>> Hi Ivan, could you raise a JIRA for this and if possible attach to it
>> the sca contribution you're trying to get to work, and I or someone
>> else will try to get it fixed for you.
>>     
>
> Hi!
> Many thanks!
> I did try to look into the problem myself, but after four hours, I just
> felt like I had been walking around in circles. :-P
> I have prepared a unit test and will create a JIRA as soon as I have a
> little more time (later next week, I guess).
> Note that this issue is in no way critical to me and I am not in a hurry.
> Best wishes!
>  Ivan
>
>   
Hello again!
After some more digging, I have found that there is already a unit test
that fails with a NullPointerException during circumstances that seems
indentical to those I have experienced.
So, before creatinga JIRA entry, I want to check with others to make
sure that this is not an isolated issue I am experiencing.
The unit test in question is:
Package: org.apache.tuscany.sca.deployment.impl
Class: DeployerImplTestCase
Method: testBuild

Thanks and best wishes!
 Ivan

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by keinmensch <ke...@mailhaven.com>.
ant elder wrote:
> Hi Ivan, could you raise a JIRA for this and if possible attach to it
> the sca contribution you're trying to get to work, and I or someone
> else will try to get it fixed for you.

Hi!
Many thanks!
I did try to look into the problem myself, but after four hours, I just
felt like I had been walking around in circles. :-P
I have prepared a unit test and will create a JIRA as soon as I have a
little more time (later next week, I guess).
Note that this issue is in no way critical to me and I am not in a hurry.
Best wishes!
 Ivan

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by ant elder <an...@gmail.com>.
Hi Ivan, could you raise a JIRA for this and if possible attach to it
the sca contribution you're trying to get to work, and I or someone
else will try to get it fixed for you.

   ...ant

On Thu, Dec 17, 2009 at 5:40 PM, Raymond Feng <en...@gmail.com> wrote:
> The property compatibility check we have in Tuscany seems to be too
> restrictive. In your case, the componentType property is declared in java
> and no XSD element can be inferred.
>
> The SCA assembly spec says:
>
> 1109 Two property types are compatible if they have the same XSD type (where
> declared as XSD types) or the
> 1110 same XSD global element (where declared as XSD global elements). For
> cases where the type of a
> 1111 property is declared using a different type system (eg Java), then the
> type of the property is mapped to
> 1112 XSD using the mapping rules defined by the appropriate implementation
> type specification
>
> If the mapped XSD type for the java property (componentType property) is the
> same as the one behind the XSD global element for the component property, we
> should take them as compatible.
>
> Thanks,
> Raymond
> --------------------------------------------------
> From: "keinmensch" <ke...@mailhaven.com>
> Sent: Thursday, December 17, 2009 6:46 AM
> To: <us...@tuscany.apache.org>
> Subject: Re: Non-Simple Property Injected with XML Fails with NPE
>
>> Hi again!
>> So, I have become desperate :-) and started poking around in the Tuscany
>> source code.
>> The NullPointerException that I experienced earlier is caused by a
>> component type property having a null XSD element. I modified the code,
>> as below, to avoid the NullPointerException.
>> [code]
>> ...
>>           // check that the types specified in the component type and
>> component property match
>>           if (componentProperty.getXSDElement() != null
>>               && !componentProperty.getXSDElement().equals(
>>                   componentTypeProperty.getXSDElement()))
>>           {
>>               // MY MODIFICATION HERE.
>>               String theCompTypePropXSDElem = "[not available]";
>>               if (componentTypeProperty
>>                       .getXSDElement() != null)
>>               {
>>                   theCompTypePropXSDElem =
>> componentTypeProperty.getXSDElement().toString();
>>               }
>>               Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION,
>>                   "PropertXSDElementsDontMatch", component.getName(),
>>                   componentProperty.getName(), componentProperty
>>                       .getXSDElement().toString(),
>> theCompTypePropXSDElem);
>>           }
>> ...
>> [/code]
>>
>> With this modification in place, I now receive the following messages in
>> the log:
>>
>> Dec 17, 2009 10:28:54 PM
>> org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl [Composite:
>> {http://docs.oasis-open.org/ns/opencsa/sca/200
>> 903}, Component: ServiceComponent1] (PropertXSDElementsDontMatch)
>> SEVERE: [ASM_5036] The property component ServiceComponent1 property
>> myComplexProp has XSD element {http://foo.com}fooElement while its comp
>> onent type property has the XSD element [not available]
>> java.lang.IllegalStateException:
>> org.oasisopen.sca.ServiceRuntimeException: [Composite:
>> {http://docs.oasis-open.org/ns/opencsa/sca/200903},
>> Component: ServiceComponent1] - [ASM_5036] The property component
>> ServiceComponent1 property myComplexProp has XSD element {http://foo.com}f
>> ooElement while its component type property has the XSD element [not
>> available]
>>   at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:176)
>>   at
>>
>> com.ivan.SmallPropertyTestMain.doStuffTuscany2(SmallPropertyTestMain.java:58)
>>   at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:29)
>> Caused by: org.oasisopen.sca.ServiceRuntimeException: [Composite:
>> {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: ServiceComp
>> onent1] - [ASM_5036] The property component ServiceComponent1 property
>> myComplexProp has XSD element {http://foo.com}fooElement while its co
>> mponent type property has the XSD element [not available]
>>   at
>>
>> org.apache.tuscany.sca.node.impl.NodeFactoryImpl.analyzeProblems(NodeFactoryImpl.java:174)
>>   at
>>
>> org.apache.tuscany.sca.node.impl.NodeFactoryImpl.configureNode(NodeFactoryImpl.java:275)
>>   at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:135)
>>   ... 2 more
>> Exception in thread "main" java.lang.NullPointerException
>>   at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:31)
>>
>> The question is: Why is the component type property null?
>> Isn't the property type supposed to be inferred from the field annotated
>> by the @Property annotation or have I misunderstood?
>> Best wishes,
>> Ivan
>
>

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by Raymond Feng <en...@gmail.com>.
The property compatibility check we have in Tuscany seems to be too 
restrictive. In your case, the componentType property is declared in java 
and no XSD element can be inferred.

The SCA assembly spec says:

1109 Two property types are compatible if they have the same XSD type (where 
declared as XSD types) or the
1110 same XSD global element (where declared as XSD global elements). For 
cases where the type of a
1111 property is declared using a different type system (eg Java), then the 
type of the property is mapped to
1112 XSD using the mapping rules defined by the appropriate implementation 
type specification

If the mapped XSD type for the java property (componentType property) is the 
same as the one behind the XSD global element for the component property, we 
should take them as compatible.

Thanks,
Raymond
--------------------------------------------------
From: "keinmensch" <ke...@mailhaven.com>
Sent: Thursday, December 17, 2009 6:46 AM
To: <us...@tuscany.apache.org>
Subject: Re: Non-Simple Property Injected with XML Fails with NPE

> Hi again!
> So, I have become desperate :-) and started poking around in the Tuscany
> source code.
> The NullPointerException that I experienced earlier is caused by a
> component type property having a null XSD element. I modified the code,
> as below, to avoid the NullPointerException.
> [code]
> ...
>            // check that the types specified in the component type and
> component property match
>            if (componentProperty.getXSDElement() != null
>                && !componentProperty.getXSDElement().equals(
>                    componentTypeProperty.getXSDElement()))
>            {
>                // MY MODIFICATION HERE.
>                String theCompTypePropXSDElem = "[not available]";
>                if (componentTypeProperty
>                        .getXSDElement() != null)
>                {
>                    theCompTypePropXSDElem =
> componentTypeProperty.getXSDElement().toString();
>                }
>                Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION,
>                    "PropertXSDElementsDontMatch", component.getName(),
>                    componentProperty.getName(), componentProperty
>                        .getXSDElement().toString(),
> theCompTypePropXSDElem);
>            }
> ...
> [/code]
>
> With this modification in place, I now receive the following messages in
> the log:
>
> Dec 17, 2009 10:28:54 PM
> org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl [Composite:
> {http://docs.oasis-open.org/ns/opencsa/sca/200
> 903}, Component: ServiceComponent1] (PropertXSDElementsDontMatch)
> SEVERE: [ASM_5036] The property component ServiceComponent1 property
> myComplexProp has XSD element {http://foo.com}fooElement while its comp
> onent type property has the XSD element [not available]
> java.lang.IllegalStateException:
> org.oasisopen.sca.ServiceRuntimeException: [Composite:
> {http://docs.oasis-open.org/ns/opencsa/sca/200903},
> Component: ServiceComponent1] - [ASM_5036] The property component
> ServiceComponent1 property myComplexProp has XSD element {http://foo.com}f
> ooElement while its component type property has the XSD element [not
> available]
>    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:176)
>    at
> com.ivan.SmallPropertyTestMain.doStuffTuscany2(SmallPropertyTestMain.java:58)
>    at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:29)
> Caused by: org.oasisopen.sca.ServiceRuntimeException: [Composite:
> {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: ServiceComp
> onent1] - [ASM_5036] The property component ServiceComponent1 property
> myComplexProp has XSD element {http://foo.com}fooElement while its co
> mponent type property has the XSD element [not available]
>    at
> org.apache.tuscany.sca.node.impl.NodeFactoryImpl.analyzeProblems(NodeFactoryImpl.java:174)
>    at
> org.apache.tuscany.sca.node.impl.NodeFactoryImpl.configureNode(NodeFactoryImpl.java:275)
>    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:135)
>    ... 2 more
> Exception in thread "main" java.lang.NullPointerException
>    at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:31)
>
> The question is: Why is the component type property null?
> Isn't the property type supposed to be inferred from the field annotated
> by the @Property annotation or have I misunderstood?
> Best wishes,
> Ivan 


Re: Non-Simple Property Injected with XML Fails with NPE

Posted by keinmensch <ke...@mailhaven.com>.
Hi again!
So, I have become desperate :-) and started poking around in the Tuscany
source code.
The NullPointerException that I experienced earlier is caused by a
component type property having a null XSD element. I modified the code,
as below, to avoid the NullPointerException.
[code]
...
            // check that the types specified in the component type and
component property match
            if (componentProperty.getXSDElement() != null
                && !componentProperty.getXSDElement().equals(
                    componentTypeProperty.getXSDElement()))
            {
                // MY MODIFICATION HERE.
                String theCompTypePropXSDElem = "[not available]";
                if (componentTypeProperty
                        .getXSDElement() != null)
                {
                    theCompTypePropXSDElem =
componentTypeProperty.getXSDElement().toString();
                }
                Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION,
                    "PropertXSDElementsDontMatch", component.getName(),
                    componentProperty.getName(), componentProperty
                        .getXSDElement().toString(),
theCompTypePropXSDElem);
            }
...
[/code]

With this modification in place, I now receive the following messages in
the log:

Dec 17, 2009 10:28:54 PM
org.apache.tuscany.sca.builder.impl.ComponentBuilderImpl [Composite:
{http://docs.oasis-open.org/ns/opencsa/sca/200
903}, Component: ServiceComponent1] (PropertXSDElementsDontMatch)
SEVERE: [ASM_5036] The property component ServiceComponent1 property
myComplexProp has XSD element {http://foo.com}fooElement while its comp
onent type property has the XSD element [not available]
java.lang.IllegalStateException:
org.oasisopen.sca.ServiceRuntimeException: [Composite:
{http://docs.oasis-open.org/ns/opencsa/sca/200903},
Component: ServiceComponent1] - [ASM_5036] The property component
ServiceComponent1 property myComplexProp has XSD element {http://foo.com}f
ooElement while its component type property has the XSD element [not
available]
    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:176)
    at
com.ivan.SmallPropertyTestMain.doStuffTuscany2(SmallPropertyTestMain.java:58)
    at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:29)
Caused by: org.oasisopen.sca.ServiceRuntimeException: [Composite:
{http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: ServiceComp
onent1] - [ASM_5036] The property component ServiceComponent1 property
myComplexProp has XSD element {http://foo.com}fooElement while its co
mponent type property has the XSD element [not available]
    at
org.apache.tuscany.sca.node.impl.NodeFactoryImpl.analyzeProblems(NodeFactoryImpl.java:174)
    at
org.apache.tuscany.sca.node.impl.NodeFactoryImpl.configureNode(NodeFactoryImpl.java:275)
    at org.apache.tuscany.sca.node.impl.NodeImpl.start(NodeImpl.java:135)
    ... 2 more
Exception in thread "main" java.lang.NullPointerException
    at com.ivan.SmallPropertyTestMain.main(SmallPropertyTestMain.java:31)

The question is: Why is the component type property null?   
Isn't the property type supposed to be inferred from the field annotated
by the @Property annotation or have I misunderstood?
Best wishes,
 Ivan

Re: Non-Simple Property Injected with XML Fails with NPE

Posted by keinmensch <ke...@mailhaven.com>.
Hi again!
I have managed to write an example program that works in Tuscany 1.5.1,
but fails in Tuscany 2.0M4, in case it is of interest.
Best regards!
 Ivan