commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
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 GMT
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
+ * <a href="https://issues.apache.org/jira/browse/BEANUTILS-456">JIRA issue
+ * BEANUTILS-456</a>.
+ *
+ * @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));
+    }
+}



Mime
View raw message