commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <benerit...@googlemail.com>
Subject Re: [BeanUtils2] In what cases can we expect to see an IllegalAccessException?
Date Thu, 21 Jun 2012 08:27:00 GMT
Hi Simo,

2012/6/21 Simone Tripodi <simonetripodi@apache.org>:
> Hi Bene,
>
> I'll need some time to read you email, I am close to a deadline and
> still have few task to complete.
>

no problem!

> In the meanwhile, I'd sugest you to move exceptions outside the
> `exception` package and drop it - exceptions should be packaged at
> APIs level, not by their nature.
>
> Have a look, just to mention a good example, at IOException[1] and
> (some of) derivates - they are in the java.io, not java.io.exception
>
> java.io.InputStream#read() throws java.io.IOException
>
> Of course, there are also samples (not in the JDK that I know) where
> exceptions are packaged in `exception(s)` package but... would you
> move interfaces in the `interface(s)`? I wouldn't :P Just kidding ;)
>

Many thanks for this suggestion! I never thought about it from that
side, but you're absolutely right. I'll change it.

Benedikt

> best and thanks in advance for the hard work,
> -Simo
>
> [1] http://docs.oracle.com/javase/6/docs/api/java/io/IOException.html
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
>
> On Wed, Jun 20, 2012 at 9:52 PM, Benedikt Ritter
> <beneritter@googlemail.com> wrote:
>> Hi,
>>
>> I'm still working on https://issues.apache.org/jira/browse/SANDBOX-423
>> and I wanted to test if all the new exception get thrown correctly.
>> For that reason I implemented a new class - ExceptionThrowingTestBean
>> that properties and methods that throw exceptions when they get
>> called. That way I can test if the InvocationTargetException gets
>> wrapped correctly in.
>>
>> I also implemented getters and setters with default, protected and
>> private visibility. I expected to get an IllegalAccessException
>> wrapped in a PropertyNotAccessibleException. Instead I got:
>>
>> java.lang.Exception: Unexpected exception,
>> expected<org.apache.commons.beanutils2.exception.PropertyNotAccessibleException>
>> but was<org.apache.commons.beanutils2.exception.PropertyNotFoundException>
>>        at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:31)
>>        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
>>        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
>>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
>>        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>>        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>>        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>>        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>>        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>>        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
>>        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>>        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>> Caused by: org.apache.commons.beanutils2.exception.PropertyNotFoundException:
>> Property privateProperty not found in type
>> org.apache.commons.beanutils2.testbeans.ExceptionThrowingTestBean
>>        at org.apache.commons.beanutils2.DefaultBeanAccessor.get(DefaultBeanAccessor.java:73)
>>        at org.apache.commons.beanutils2.GetPropertyTestCase.getPrivateProperty(GetPropertyTestCase.java:93)
>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>        at java.lang.reflect.Method.invoke(Method.java:601)
>>        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
>>        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
>>        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>        at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:22)
>>        ... 17 more
>> Caused by: java.beans.IntrospectionException: Property
>> 'privateProperty' does not exist in bean of type
>> org.apache.commons.beanutils2.testbeans.ExceptionThrowingTestBean
>>        at org.apache.commons.beanutils2.DefaultBeanProperties.getPropertyDescriptor(DefaultBeanProperties.java:106)
>>        at org.apache.commons.beanutils2.DefaultBeanProperties.getReadPropertyMethod(DefaultBeanProperties.java:119)
>>        at org.apache.commons.beanutils2.DefaultBeanAccessor.get(DefaultBeanAccessor.java:65)
>>        ... 27 more
>>
>> I believe this is, because somewhere deep inside
>> AccessibleObjectsRegistry everthing that is not public will be ignored
>> (see line 352 in that class). So the AccessibleObjectsRegistry returns
>> null for a property getter that is not accessible. Is this an
>> acceptable behavior or do we have to change that?
>>
>> I believe that even if the user code has access to a
>> method/property/constructor, the BU2 code won't have access. This is
>> because client code may reside in the same class (private visibility),
>> package (default visibility) or in an inheriting class (protected
>> visibility), but the code that actually calls the methods is in BU2
>> and won't have access. Am I right? What do we do about that?
>>
>> My suggestion would be instead of returning null (line 354) in
>> AccessibleObjectsRegistry, we could throw an IllegalAccessException
>> that could be caught and wrapped later on. What do you think?
>>
>> Regrads,
>> Benedikt
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

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


Mime
View raw message