Forwarding, as I accidentally hit "reply to" instead of "reply to all" and it only went to Mike.
Jim
Begin forwarded message: Date: January 17, 2010 2:19:28 PM GMT+01:00 Subject: Re: [sca-assembly] [ISSUE 201]: Test 6019 assumed injection behavior
On Jan 13, 2010, at 11:18 AM, Mike Edwards wrote: Jim, I've added this to the JIRA. I'm not against adding the null check, however, if you think that this will enable your runtime to pass in a null for the array/collection, then you are going to fail one of the tests in the Java test suite which check specifically for what is injected under various circumstances.
Fabric3 can be configured to support either of the scenarios so I'm raising this less for practical reasons than philosophical.
If you REALLY want null to be acceptable, then please raise an issue in the Java TC, but please note that the current position was subject to a previous issue and a quite prolonged debate.
Unfortunately I missed the first debate and generally dislike revisiting closed issues. I am going to think about this some more but my leaning right now is to try and get the issue reopened as I think this behavior makes SCA Java code more complex and prohibits runtime optimizations. Yours, Mike. Strategist - Emerging Technologies, SCA & SDO. Co Chair OASIS SCA Assembly TC. IBM Hursley Park, Mail Point 146, Winchester, SO21 2JN, Great Britain. Phone & FAX: +44-1962-818014 Mobile: +44-7802-467431 Email: mike_edwards@uk.ibm.com FYI, The proposed solution code left out a null check, which was supposed to be the main point :-) Here is a revised version:
@Service(Service1.class) public class service1Impl4 implements Service1 { @Property public String serviceName = "service1"; @Reference(required=false) public Service1[] reference1; public String operation1(String input) { StringBuilder result = new StringBuilder(serviceName).append(" operation1 invoked"); if (reference1 == null) { return result.toString(); } for (Service1 aReference1 : reference1) { String value = aReference1.operation1(input); result = result.append(" ").append(value); } return result.toString(); } } Jim On Jan 12, 2010, at 10:19 AM, Mike Edwards wrote:
Logged as: http://www.osoa.org/jira/browse/ASSEMBLY-201 Yours, Mike. Strategist - Emerging Technologies, SCA & SDO. Co Chair OASIS SCA Assembly TC. IBM Hursley Park, Mail Point 146, Winchester, SO21 2JN, Great Britain. Phone & FAX: +44-1962-818014 Mobile: +44-7802-467431 Email: mike_edwards@uk.ibm.com
TARGET: SCA Assembly Conformance Tests DESCRIPTION: Test case ASM_6019 verifies an autowire reference with multiplicity 0..n that has no matching services still runs. The component implementation, org.oasisopen.sca.test.service1Impl4, has an array type for the autowire reference. The operation that is invoked on that implementation iterates the array and invokes wired services without checking for null. Some runtimes may not inject the reference if no matching wires are found. Consequently, this results in an NPE since the reference member variable is not set: @Service(Service1.class) public class service1Impl4 implements Service1 { @Property public String serviceName = "service1"; // Required = false + an array -> multiplicity 0..n @Reference(required=false) public Service1[] reference1 = null; public String operation1(String input) { String result = serviceName + " operation1 invoked"; // Call each of the references in the array, concatenating the results for( int i=0 ; i < reference1.length; i++ ) { result = result.concat(" "); result = result.concat( reference1[i].operation1(input) ); } // end for return result; } } SVN Version: 426 PROPOSAL: Code defensively, assuming the reference may not be injected. A potential replacement is: @Service(Service1.class) public class service1Impl4 implements Service1 { @Property public String serviceName = "service1"; @Reference(required=false) public Service1[] reference1; public String operation1(String input) { StringBuilder result = new StringBuilder(serviceName).append(" operation1 invoked"); for (Service1 aReference1 : reference1) { String value = aReference1.operation1(input); result = result.append(" ").append(value); } return result.toString(); } } --------------------------------------------------------------------- To unsubscribe from this mail list, you must leave the OASIS TC that generates this mail. Follow this link to all your TCs in OASIS at: https://www.oasis-open.org/apps/org/workgroup/portal/my_workgroups.php
Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
|