You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Henning P. Schmiedehausen" <hp...@intermeta.de> on 2003/10/13 09:57:38 UTC

[BEANUTILS] Property Descriptor visibility

Hi,

consider the following beans:

--- cut ---
package beans;

abstract class AbstractBean {
  private String foo = null;

  public AbstractBean() {}

  public String getFoo() { return this.foo; };

  public void setFoo(String foo) { this.foo = foo; };
}
--- cut ---

--- cut ---
package beans;

public class PublicBean
  extends AbstractBean {
  private String bar = null;

  public PublicBeanBean() { super(); }

  public String getBar() { return this.bar; };

  public void setBar(String bar) { this.bar = bar; };
}
--- cut ---

import beans.PublicBean;
[...]
PublicBean bean = new PublicBean();
BeanUtils.setSimpleProperty(bean,  "foo", "value");

fails. The reason for this is the Property visibility check in the
MethodUtils::getAccessibleMethod, which considers the "setFoo/getFoo"
Property setters to be inaccessible because they're not defined in a
public class and not defined by any Interface implemented by the Bean.

My question now is: Is this correct? The public visibility of the
PublicBean class makes IMHO the public methods AbstractBean::setFoo()
and AbstractBean::getFoo() accessible, even if the declaring class
(AbstractBean) is not public.

This is not an academic question, it is exactly the problem I've
written about yesterday with commons-dbcp. There is "public
SharedPoolDataSource" which extends "abstract
InstanceKeyDataSource". One cannot set properties defined in
InstanceKeyDataSource with PropertyUtils because of this problem.

I'd be interested if the correct solution is to add a "public" to
InstanceKeyDataSource or rewrite the MethodUtils::getAccessibleMethod().

	Regards
		Henning

-- 

"In einem Abw�gungsprozess, wollen wir weiter regieren, hat sich die
SPD und die Bundesregierung und auch der Bundesfinanzminister f�rs
Weiterregieren entschieden und gegen die Ehrlichkeit" -- Oswald
Metzger, B�ndnis '90/Die Gr�nen, 12.11.2002

-- 
Henning Schmiedehausen     "We're Germans and we use Unix. 
hps@intermeta.de            That's a combination of two demographic groups
henning@forge.franken.de    known to have no sense of humour whatsoever."
                               -- Hanno Mueller in de.comp.os.unix.programming 



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: [BEANUTILS] Property Descriptor visibility

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:

>Henning - I assume this was meant for the commons list?

Yep. Slip of hand. Sorry. I will repost there.

	Regards
		Henning



>geir

>On Monday, October 13, 2003, at 03:57 AM, Henning P. Schmiedehausen 
>wrote:

>> Hi,
>>
>> consider the following beans:
>>
>> --- cut ---
>> package beans;
>>
>> abstract class AbstractBean {
>>   private String foo = null;
>>
>>   public AbstractBean() {}
>>
>>   public String getFoo() { return this.foo; };
>>
>>   public void setFoo(String foo) { this.foo = foo; };
>> }
>> --- cut ---
>>
>> --- cut ---
>> package beans;
>>
>> public class PublicBean
>>   extends AbstractBean {
>>   private String bar = null;
>>
>>   public PublicBeanBean() { super(); }
>>
>>   public String getBar() { return this.bar; };
>>
>>   public void setBar(String bar) { this.bar = bar; };
>> }
>> --- cut ---
>>
>> import beans.PublicBean;
>> [...]
>> PublicBean bean = new PublicBean();
>> BeanUtils.setSimpleProperty(bean,  "foo", "value");
>>
>> fails. The reason for this is the Property visibility check in the
>> MethodUtils::getAccessibleMethod, which considers the "setFoo/getFoo"
>> Property setters to be inaccessible because they're not defined in a
>> public class and not defined by any Interface implemented by the Bean.
>>
>> My question now is: Is this correct? The public visibility of the
>> PublicBean class makes IMHO the public methods AbstractBean::setFoo()
>> and AbstractBean::getFoo() accessible, even if the declaring class
>> (AbstractBean) is not public.
>>
>> This is not an academic question, it is exactly the problem I've
>> written about yesterday with commons-dbcp. There is "public
>> SharedPoolDataSource" which extends "abstract
>> InstanceKeyDataSource". One cannot set properties defined in
>> InstanceKeyDataSource with PropertyUtils because of this problem.
>>
>> I'd be interested if the correct solution is to add a "public" to
>> InstanceKeyDataSource or rewrite the 
>> MethodUtils::getAccessibleMethod().
>>
>> 	Regards
>> 		Henning
>>
>> -- 
>>
>> "In einem Abw�gungsprozess, wollen wir weiter regieren, hat sich die
>> SPD und die Bundesregierung und auch der Bundesfinanzminister f�rs
>> Weiterregieren entschieden und gegen die Ehrlichkeit" -- Oswald
>> Metzger, B�ndnis '90/Die Gr�nen, 12.11.2002
>>
>> -- 
>> Henning Schmiedehausen     "We're Germans and we use Unix.
>> hps@intermeta.de            That's a combination of two demographic 
>> groups
>> henning@forge.franken.de    known to have no sense of humour 
>> whatsoever."
>>                                -- Hanno Mueller in 
>> de.comp.os.unix.programming
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
>-- 
>Geir Magnusson Jr                                   203-247-1713(m)
>geirm@optonline.net


>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

"Dominate!! Dominate!! Eat your young and aggregate! I have grotty silicon!" 
      -- AOL CD when played backwards  (User Friendly - 200-10-15)

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: [BEANUTILS] Property Descriptor visibility

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Henning - I assume this was meant for the commons list?

geir

On Monday, October 13, 2003, at 03:57 AM, Henning P. Schmiedehausen 
wrote:

> Hi,
>
> consider the following beans:
>
> --- cut ---
> package beans;
>
> abstract class AbstractBean {
>   private String foo = null;
>
>   public AbstractBean() {}
>
>   public String getFoo() { return this.foo; };
>
>   public void setFoo(String foo) { this.foo = foo; };
> }
> --- cut ---
>
> --- cut ---
> package beans;
>
> public class PublicBean
>   extends AbstractBean {
>   private String bar = null;
>
>   public PublicBeanBean() { super(); }
>
>   public String getBar() { return this.bar; };
>
>   public void setBar(String bar) { this.bar = bar; };
> }
> --- cut ---
>
> import beans.PublicBean;
> [...]
> PublicBean bean = new PublicBean();
> BeanUtils.setSimpleProperty(bean,  "foo", "value");
>
> fails. The reason for this is the Property visibility check in the
> MethodUtils::getAccessibleMethod, which considers the "setFoo/getFoo"
> Property setters to be inaccessible because they're not defined in a
> public class and not defined by any Interface implemented by the Bean.
>
> My question now is: Is this correct? The public visibility of the
> PublicBean class makes IMHO the public methods AbstractBean::setFoo()
> and AbstractBean::getFoo() accessible, even if the declaring class
> (AbstractBean) is not public.
>
> This is not an academic question, it is exactly the problem I've
> written about yesterday with commons-dbcp. There is "public
> SharedPoolDataSource" which extends "abstract
> InstanceKeyDataSource". One cannot set properties defined in
> InstanceKeyDataSource with PropertyUtils because of this problem.
>
> I'd be interested if the correct solution is to add a "public" to
> InstanceKeyDataSource or rewrite the 
> MethodUtils::getAccessibleMethod().
>
> 	Regards
> 		Henning
>
> -- 
>
> "In einem Abwägungsprozess, wollen wir weiter regieren, hat sich die
> SPD und die Bundesregierung und auch der Bundesfinanzminister fürs
> Weiterregieren entschieden und gegen die Ehrlichkeit" -- Oswald
> Metzger, Bündnis '90/Die Grünen, 12.11.2002
>
> -- 
> Henning Schmiedehausen     "We're Germans and we use Unix.
> hps@intermeta.de            That's a combination of two demographic 
> groups
> henning@forge.franken.de    known to have no sense of humour 
> whatsoever."
>                                -- Hanno Mueller in 
> de.comp.os.unix.programming
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geirm@optonline.net


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org