You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Bram Pouwelse <br...@pouwelse.com> on 2017/08/24 19:21:32 UTC

DM r11 Behavior change in Component.getServiceProperties() intentional?

Hi all,

The behavior of Component.getServiceProperties() changed in the r11
release. Since this release the getServiceProperties method returns null if
instead of an emtpy dictionary, this seems to be in-line with the javadoc
(@return the properties or <code>null</code> if there are none) but it used
to return the emtpty dictionary in the past.

We have some errors due to this in several of our projects as in the past
initializing a component with emtpy properties was a nice way to make sure
that you never got a null from component.getServiceProperties().

If you do something like (simplified)
Component component = m_dependencyManager
.createComponent().setInterface(ApplicationService.class.getName(), new
Properties())
component.getServiceProperties().put("a", "b");

This now results in an NPE.

Had a quick look at the history and I think the change is due to the fix
for this FELIX-5636 [1], on github [2].

Long story, I'm mainly wondering if the change in behavior is intentional
or not.

Regards,
Bram

[1] https://issues.apache.org/jira/browse/FELIX-5636
[2]
https://github.com/apache/felix/commit/cfb4f0daccd8d940b6acc069b7376f2dd9e92395#diff-d4572933aed00f00ea9594c93598d2f2L682

Re: DM r11 Behavior change in Component.getServiceProperties() intentional?

Posted by Pierre De Rop <pi...@gmail.com>.
Hi Bram,

The NPE from your sample code is caused by a regression made in r9 release.
I have created a FELIX-5683 issue, and committed the corresponding fix,
which avoids the NPE.

But there is another issue, because if I'm correct, since the initial
version of dm (2.0.1), the getServiceProperties() method returns a copy of
the service properties dictionary maintained in the component impl.  So if
you would like to set service properties like the example you provided, it
won't won't work because the "component.getServiceProperties().put("a",
"b")" will set the property in the copy returned by the
getServiceProperties() method.

can you please have a look at
https://issues.apache.org/jira/browse/FELIX-5683, and comment it ?
can you also checkout the trunk and see if the NPE is now fixed ?

thanks and sorry for the regression;

cheers
Pierre

On Thu, Aug 24, 2017 at 9:21 PM, Bram Pouwelse <br...@pouwelse.com> wrote:

> Hi all,
>
> The behavior of Component.getServiceProperties() changed in the r11
> release. Since this release the getServiceProperties method returns null if
> instead of an emtpy dictionary, this seems to be in-line with the javadoc
> (@return the properties or <code>null</code> if there are none) but it used
> to return the emtpty dictionary in the past.
>
> We have some errors due to this in several of our projects as in the past
> initializing a component with emtpy properties was a nice way to make sure
> that you never got a null from component.getServiceProperties().
>
> If you do something like (simplified)
> Component component = m_dependencyManager
> .createComponent().setInterface(ApplicationService.class.getName(), new
> Properties())
> component.getServiceProperties().put("a", "b");
>
> This now results in an NPE.
>
> Had a quick look at the history and I think the change is due to the fix
> for this FELIX-5636 [1], on github [2].
>
> Long story, I'm mainly wondering if the change in behavior is intentional
> or not.
>
> Regards,
> Bram
>
> [1] https://issues.apache.org/jira/browse/FELIX-5636
> [2]
> https://github.com/apache/felix/commit/cfb4f0daccd8d940b6acc069b7376f
> 2dd9e92395#diff-d4572933aed00f00ea9594c93598d2f2L682
>