Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B6FBB10446 for ; Fri, 3 Jan 2014 19:38:03 +0000 (UTC) Received: (qmail 44988 invoked by uid 500); 3 Jan 2014 19:38:03 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 44937 invoked by uid 500); 3 Jan 2014 19:38:03 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 44930 invoked by uid 99); 3 Jan 2014 19:38:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 19:38:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 19:38:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 76A3D23888D7; Fri, 3 Jan 2014 19:37:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1555230 - in /commons/proper/beanutils/trunk/src: main/java/org/apache/commons/beanutils/PropertyUtilsBean.java test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java Date: Fri, 03 Jan 2014 19:37:39 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140103193739.76A3D23888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Fri Jan 3 19:37:39 2014 New Revision: 1555230 URL: http://svn.apache.org/r1555230 Log: [BEANUTILS-456] Recover lost references to write methods. When querying a write method for a property descriptor the method is automatically fetched again if its reference was freed. Added a test case exposing the problem. Added: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java?rev=1555230&r1=1555229&r2=1555230&view=diff ============================================================================== --- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java (original) +++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java Fri Jan 3 19:37:39 2014 @@ -1297,7 +1297,9 @@ public class PropertyUtilsBean { * @return The write method */ Method getWriteMethod(Class clazz, PropertyDescriptor descriptor) { - return (MethodUtils.getAccessibleMethod(clazz, descriptor.getWriteMethod())); + BeanIntrospectionData data = getIntrospectionData(clazz); + return (MethodUtils.getAccessibleMethod(clazz, + data.getWriteMethod(clazz, descriptor))); } Added: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java?rev=1555230&view=auto ============================================================================== --- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java (added) +++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira456TestCase.java Fri Jan 3 19:37:39 2014 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.beanutils.bugs; + +import java.beans.PropertyDescriptor; + +import junit.framework.TestCase; + +import org.apache.commons.beanutils.FluentIntrospectionTestBean; +import org.apache.commons.beanutils.FluentPropertyBeanIntrospector; +import org.apache.commons.beanutils.PropertyUtilsBean; + +/** + * Write methods for PropertyDescriptors created during custom introspection are lost. See + * JIRA issue + * BEANUTILS-456. + * + * @version $Id: $ + */ +public class Jira456TestCase extends TestCase { + /** Constant for the name of the test property. */ + private static final String TEST_PROP = "fluentGetProperty"; + + /** The PropertyUtilsBean used by the tests. */ + private PropertyUtilsBean pub; + + @Override + protected void setUp() throws Exception { + super.setUp(); + pub = new PropertyUtilsBean(); + pub.addBeanIntrospector(new FluentPropertyBeanIntrospector()); + } + + /** + * Clears the reference to the write method in the property descriptor of the test + * property. This simulates that the write method reference is freed by the GC. + * + * @return the bean instance used for testing + * @throws Exception if an error occurs + */ + private FluentIntrospectionTestBean clearWriteMethodRef() throws Exception { + FluentIntrospectionTestBean bean = new FluentIntrospectionTestBean(); + PropertyDescriptor pd = pub.getPropertyDescriptor(bean, TEST_PROP); + + // simulate that the write method reference is freed + pd.setWriteMethod(null); + return bean; + } + + /** + * Tests whether a lost write method is automatically recovered and can be invoked. + */ + public void testWriteMethodRecover() throws Exception { + FluentIntrospectionTestBean bean = clearWriteMethodRef(); + final String value = "Test value"; + pub.setProperty(bean, TEST_PROP, value); + assertEquals("Property not set", value, bean.getFluentGetProperty()); + } + + /** + * Tests whether a property is recognized as writable even if the reference to its + * write method was freed. + */ + public void testPropertyIsWritable() throws Exception { + FluentIntrospectionTestBean bean = clearWriteMethodRef(); + assertTrue("Not writable", pub.isWriteable(bean, TEST_PROP)); + } +}