Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49B75C2C9 for ; Mon, 25 Jun 2012 20:16:23 +0000 (UTC) Received: (qmail 37758 invoked by uid 500); 25 Jun 2012 20:16:23 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 37388 invoked by uid 500); 25 Jun 2012 20:16:22 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 37374 invoked by uid 99); 25 Jun 2012 20:16:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jun 2012 20:16:22 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of simone.tripodi@gmail.com designates 209.85.215.171 as permitted sender) Received: from [209.85.215.171] (HELO mail-ey0-f171.google.com) (209.85.215.171) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jun 2012 20:16:16 +0000 Received: by eaaa12 with SMTP id a12so2345871eaa.30 for ; Mon, 25 Jun 2012 13:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=udGwcRPKGFGAcnH61p5fF29NdTbot9c2bEjoP8iN3l8=; b=m5UQiby/MEyjemYEF6JFr+02UTY1Cf9Y58hVisHwrUXEpdQp0x/5NgNI3qb4cYnDAy ukFUM3SeTCe2NCVNPRg+YgfJJPhUtvvDXZWrAsvk3b/giL9mHtwD+8gxKAQ6PaMR0Ntv /BBul45zN+ReDyZ2mu0LZWf4ZrMEtqwUrD+erp7i9dPBdvJbhXuFVzd6Th90wm3MzapS ExtB92ZdSzxkWiFhgKQgvtByCQsydxxvVGYQyxF3OlMx/AoGK5Pj8mJwej7BVONpIBQl 6uO7/ExVu3p5NbSgAS33x/WwPCeNpLVAihKr87yVas34masVjJeEQ3ymxEUC1NgO0SRV +aTQ== MIME-Version: 1.0 Received: by 10.14.188.129 with SMTP id a1mr2616889een.183.1340655355890; Mon, 25 Jun 2012 13:15:55 -0700 (PDT) Sender: simone.tripodi@gmail.com Received: by 10.14.37.1 with HTTP; Mon, 25 Jun 2012 13:15:55 -0700 (PDT) In-Reply-To: References: Date: Mon, 25 Jun 2012 22:15:55 +0200 X-Google-Sender-Auth: QM9o0HcK1GLhg6MrudpXai8_2k8 Message-ID: Subject: Re: [BeanUtils2] In what cases can we expect to see an IllegalAccessException? From: Simone Tripodi To: Commons Developers List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Bene, > 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. 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 > but was > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.statements.Expec= tException.evaluate(ExpectException.java:31) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.statements.RunBe= fores.evaluate(RunBefores.java:28) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.statements.RunAf= ters.evaluate(RunAfters.java:30) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner.runLeaf(Pare= ntRunner.java:263) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.BlockJUnit4ClassRunner.ru= nChild(BlockJUnit4ClassRunner.java:68) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.BlockJUnit4ClassRunner.ru= nChild(BlockJUnit4ClassRunner.java:47) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner$3.run(Parent= Runner.java:231) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner$1.schedule(P= arentRunner.java:60) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner.runChildren(= ParentRunner.java:229) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner.access$000(P= arentRunner.java:50) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner$2.evaluate(P= arentRunner.java:222) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.ParentRunner.run(ParentRu= nner.java:300) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit4.runner.JUni= t4TestReference.run(JUnit4TestReference.java:50) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit.runner.TestE= xecution.run(TestExecution.java:38) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit.runner.Remot= eTestRunner.runTests(RemoteTestRunner.java:467) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit.runner.Remot= eTestRunner.runTests(RemoteTestRunner.java:683) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit.runner.Remot= eTestRunner.run(RemoteTestRunner.java:390) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.eclipse.jdt.internal.junit.runner.Remot= eTestRunner.main(RemoteTestRunner.java:197) > Caused by: org.apache.commons.beanutils2.exception.PropertyNotFoundExcept= ion: > Property privateProperty not found in type > org.apache.commons.beanutils2.testbeans.ExceptionThrowingTestBean > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.apache.commons.beanutils2.DefaultBeanAc= cessor.get(DefaultBeanAccessor.java:73) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.apache.commons.beanutils2.GetPropertyTe= stCase.getPrivateProperty(GetPropertyTestCase.java:93) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at sun.reflect.NativeMethodAccessorImpl.invoke= 0(Native Method) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at sun.reflect.NativeMethodAccessorImpl.invoke= (NativeMethodAccessorImpl.java:57) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at sun.reflect.DelegatingMethodAccessorImpl.in= voke(DelegatingMethodAccessorImpl.java:43) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at java.lang.reflect.Method.invoke(Method.java= :601) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.model.FrameworkMethod$1.r= unReflectiveCall(FrameworkMethod.java:45) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.model.Reflective= Callable.run(ReflectiveCallable.java:15) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.runners.model.FrameworkMethod.inv= okeExplosively(FrameworkMethod.java:42) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.statements.Invok= eMethod.evaluate(InvokeMethod.java:20) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.junit.internal.runners.statements.Expec= tException.evaluate(ExpectException.java:22) > =C2=A0 =C2=A0 =C2=A0 =C2=A0... 17 more > Caused by: java.beans.IntrospectionException: Property > 'privateProperty' does not exist in bean of type > org.apache.commons.beanutils2.testbeans.ExceptionThrowingTestBean > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.apache.commons.beanutils2.DefaultBeanPr= operties.getPropertyDescriptor(DefaultBeanProperties.java:106) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.apache.commons.beanutils2.DefaultBeanPr= operties.getReadPropertyMethod(DefaultBeanProperties.java:119) > =C2=A0 =C2=A0 =C2=A0 =C2=A0at org.apache.commons.beanutils2.DefaultBeanAc= cessor.get(DefaultBeanAccessor.java:65) > =C2=A0 =C2=A0 =C2=A0 =C2=A0... 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! -Simo [1] http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/InvocationTa= rgetException.html#getTargetException() http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org