[ 
https://issues.apache.org/jira/browse/SANDBOX-397?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Benedikt Ritter updated SANDBOX-397:
------------------------------------

    Attachment: SANDBOX-397_SRP.txt

I have created another patch, that builds upon the first one. I think it is not 
a responsibility of a {{DefaultBeanAccessor}} to figure out, whether or not 
properties are available or not. So the private methods from the first patch 
are a violation of SRP [1].

For this reason I created a new class, that is reponsible for handling 
properties of a class: {{Properties<B>}}. I think this is a nice and clean 
solution to the SRP violation. However the patch is incomplete, because several 
unit tests fail (for details see below). I uploaded the patch anyway, because I 
want to know, what you think about the hole idea, before I start to fix the 
issues raised by the new class.

The reason for the failing tests is, that {{DefaultBeanAccessor}} creates a 
{{Properties}} object in its constructor using the bean object passed in. A 
{{DefaultBeanAccessor}} can be created in several ways:
* {{BeanUtils.on(B bean)}}
* {{ArgumentsAccessor.with(...)}}

If in the latter case, a method is invoked that returns void, instantiation of 
{{DefaultBeanAccessor}} will fail, because the constructor tries to call 
{{getClass()}} on {{null}}.

I think this is not a problem of the newly invented {{Properties<B>}} class, 
but of {{ArgumentAccessor.with(...)}}. In other words, this was broken before 
but we had no tests for this case.

A solution could be to write a Special Case [2] implementation of 
{{BeanAccessor}} for this case ({{NullBeanAccessor}}) that will be returned by 
{{ArgumentsAccessor.with(...)}} if a method returns void.

What do you think?

All the best,
Benedikt

[1] http://en.wikipedia.org/wiki/Single_responsibility_principle
[2] http://martinfowler.com/eaaCatalog/specialCase.html
                
> [BeanUtils2] Replace NullPointerExceptions been thrown in DefaultBeanAccessor 
> with NoSuchMethodEceptions
> --------------------------------------------------------------------------------------------------------
>
>                 Key: SANDBOX-397
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-397
>             Project: Commons Sandbox
>          Issue Type: Task
>          Components: BeanUtils2
>    Affects Versions: Nightly Builds
>            Reporter: Benedikt Ritter
>         Attachments: SANDBOX-397.txt, SANDBOX-397_SRP.txt
>
>
> At the moment, methods in {{DefaultBeanAccessor}} throw a 
> {{NullPointerException}}, if no {{PropertyDescriptor}} for a given property 
> name can be retrieved. As discussed on the ML (see 
> http://markmail.org/thread/zlehclmybp5xgn5n) this behavior should be changed 
> to throwing {{NoSuchMethodException}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to