commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <>
Subject Re: [BeanUtils2] In what cases can we expect to see an IllegalAccessException?
Date Mon, 25 Jun 2012 20:15:55 GMT
Hi Bene,

> I'm still working on
> 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.

a small hint: I'd focus on
InvocationTargetException.html#getTargetException() - which contains
the real cause - rather than InvocationTargetException

> 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(
>        at org.junit.internal.runners.statements.RunBefores.evaluate(
>        at org.junit.internal.runners.statements.RunAfters.evaluate(
>        at org.junit.runners.ParentRunner.runLeaf(
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(
>        at org.junit.runners.ParentRunner$
>        at org.junit.runners.ParentRunner$1.schedule(
>        at org.junit.runners.ParentRunner.runChildren(
>        at org.junit.runners.ParentRunner.access$000(
>        at org.junit.runners.ParentRunner$2.evaluate(
>        at
>        at
>        at
>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
>        at
>        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> 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(
>        at org.apache.commons.beanutils2.GetPropertyTestCase.getPrivateProperty(
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at sun.reflect.NativeMethodAccessorImpl.invoke(
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
>        at java.lang.reflect.Method.invoke(
>        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
>        at
>        at org.junit.runners.model.FrameworkMethod.invokeExplosively(
>        at org.junit.internal.runners.statements.InvokeMethod.evaluate(
>        at org.junit.internal.runners.statements.ExpectException.evaluate(
>        ... 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(
>        at org.apache.commons.beanutils2.DefaultBeanProperties.getReadPropertyMethod(
>        at org.apache.commons.beanutils2.DefaultBeanAccessor.get(
>        ... 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?

Yes I think so. Rather than just returning `null` that is confusing,
throw the proper exception.

> 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?

that is fine, but just throw the expected exception, no needs to throw
an IllegalAccessException first.

looking forward your patch, TIA!


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message