This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git


The following commit(s) were added to refs/heads/1.X by this push:
     new c0639028 Deprecate BeanUtilsBean.initCause(Throwable, Throwable) for 
removal, use Throwable.initCause(Throwable)
c0639028 is described below

commit c06390283fa37ce44bfe175906fa8c92a92e2d84
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Aug 31 09:11:05 2024 -0400

    Deprecate BeanUtilsBean.initCause(Throwable, Throwable) for removal, use
    Throwable.initCause(Throwable)
---
 src/changes/changes.xml                            |  2 +
 .../apache/commons/beanutils/BeanUtilsBean.java    | 48 ++--------------------
 2 files changed, 6 insertions(+), 44 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 48feeb91..8387b11b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -38,6 +38,8 @@
       <action dev="ggregory" type="update" due-to="Gary Gregory">Bump Java 
requirement from Java 6 to 8.</action>
       <action dev="ggregory" type="update" due-to="Gary Gregory">Bump 
junit:junit from 4.12 to 4.13.2.</action>
       <action dev="ggregory" type="update" due-to="Gary Gregory">Bump 
commons-logging:commons-logging from 1.2 to 1.3.4.</action>
+      <!-- REMOVE -->
+      <action dev="ggregory" type="update" due-to="Gary Gregory">Deprecate 
BeanUtilsBean.initCause(Throwable, Throwable) for removal, use 
Throwable.initCause(Throwable).</action>
     </release>
     <release version="1.9.4" date="2019-06-12" description="The primary reason 
for this release is a bugfix for
 CVE-2014-0114. More specifically, our goal with BEANUTILS-520
diff --git a/src/main/java/org/apache/commons/beanutils/BeanUtilsBean.java 
b/src/main/java/org/apache/commons/beanutils/BeanUtilsBean.java
index 8e181010..1bbc6333 100644
--- a/src/main/java/org/apache/commons/beanutils/BeanUtilsBean.java
+++ b/src/main/java/org/apache/commons/beanutils/BeanUtilsBean.java
@@ -15,10 +15,8 @@
  * limitations under the License.
  */
 
-
 package org.apache.commons.beanutils;
 
-
 import java.beans.IndexedPropertyDescriptor;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Array;
@@ -34,7 +32,6 @@ import org.apache.commons.beanutils.expression.Resolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
 /**
  * <p>JavaBean property population methods.</p>
  *
@@ -49,8 +46,6 @@ import org.apache.commons.logging.LogFactory;
 
 public class BeanUtilsBean {
 
-
-
     /**
      * Contains <code>BeanUtilsBean</code> instances indexed by context 
classloader.
      */
@@ -63,9 +58,6 @@ public class BeanUtilsBean {
                         }
                     };
 
-    /** A reference to Throwable's initCause method, or null if it's not there 
in this JVM */
-    private static final Method INIT_CAUSE_METHOD = getInitCauseMethod();
-
     /**
      * Determines the type of a {@code DynaProperty}. Here a special treatment
      * is needed for mapped properties.
@@ -83,34 +75,6 @@ public class BeanUtilsBean {
     }
 
 
-    /**
-     * Returns a <code>Method<code> allowing access to
-     * {@link Throwable#initCause(Throwable)} method of {@link Throwable},
-     * or <code>null</code> if the method
-     * does not exist.
-     *
-     * @return A <code>Method<code> for <code>Throwable.initCause</code>, or
-     * <code>null</code> if unavailable.
-     */
-    private static Method getInitCauseMethod() {
-        try {
-            final Class<?>[] paramsClasses = { Throwable.class };
-            return Throwable.class.getMethod("initCause", paramsClasses);
-        } catch (final NoSuchMethodException e) {
-            final Log log = LogFactory.getLog(BeanUtils.class);
-            if (log.isWarnEnabled()) {
-                log.warn("Throwable does not have initCause() method in JDK 
1.3");
-            }
-            return null;
-        } catch (final Throwable e) {
-            final Log log = LogFactory.getLog(BeanUtils.class);
-            if (log.isWarnEnabled()) {
-                log.warn("Error getting the Throwable initCause() method", e);
-            }
-            return null;
-        }
-    }
-
     /**
      * Gets the instance which provides the functionality for {@link 
BeanUtils}.
      * This is a pseudo-singleton - an single instance is provided per 
(thread) context classloader.
@@ -863,16 +827,12 @@ public class BeanUtilsBean {
      * @param  cause     The cause of the throwable.
      * @return  true if the cause was initialized, otherwise false.
      * @since 1.8.0
+     * @deprecated Use {@link Throwable#initCause(Throwable)}.
+     * @see Throwable#initCause(Throwable)
      */
+    @Deprecated
     public boolean initCause(final Throwable throwable, final Throwable cause) 
{
-        if (INIT_CAUSE_METHOD != null && cause != null) {
-            try {
-                INIT_CAUSE_METHOD.invoke(throwable, cause);
-                return true;
-            } catch (final Throwable e) {
-                // can't initialize cause
-            }
-        }
+        throwable.initCause(cause);
         return false;
     }
 

Reply via email to