Re: [commons-lang] 04/04: Throw IllegalArgumentException instead of InternalError in the builder package

2023-07-12 Thread Gary Gregory
There must be something messed up with EOLs despite my git autocrlf
settings... sorry about that.

Gary

On Wed, Jul 12, 2023, 08:51 Gilles Sadowski  wrote:

> Hi.
>
> Le mer. 12 juil. 2023 à 14:44,  a écrit :
> >
> > This is an automated email from the ASF dual-hosted git repository.
> >
> > ggregory pushed a commit to branch master
> > in repository https://gitbox.apache.org/repos/asf/commons-lang.git
> >
> > commit 2e3feda04337baa483bc26b66f238161dc6c97ac
> > Author: Gary Gregory 
> > AuthorDate: Wed Jul 12 08:44:38 2023 -0400
> >
> > Throw IllegalArgumentException instead of InternalError in the
> builder
> > package
>
> The diff below contains a bunch of (formatting ?) changes that
> have nothing to do with this commit message.
>
> Regards,
> Gilles
>
> > ---
> >  src/changes/changes.xml|   1 +
> >  .../commons/lang3/builder/CompareToBuilder.java| 752
> ++---
> >  .../commons/lang3/builder/EqualsBuilder.java   |  20 +-
> >  .../commons/lang3/builder/HashCodeBuilder.java |   9 +-
> >  .../apache/commons/lang3/builder/Reflection.java   |  44 ++
> >  .../lang3/builder/ReflectionDiffBuilder.java   |   7 +-
> >  .../lang3/builder/ReflectionToStringBuilder.java   |  14 +-
> >  7 files changed, 434 insertions(+), 413 deletions(-)
> >
> > diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> > index 26d7be48c..da3522029 100644
> > --- a/src/changes/changes.xml
> > +++ b/src/changes/changes.xml
> > @@ -123,6 +123,7 @@ The  type attribute can be
> add,update,fix,remove.
> >   due-to="Dimitrios Efthymiou">Update Javadoc for the insert methods in
> ArrayUtils #1078.
> >  Deprecate ExceptionUtils.ExceptionUtils().
> >  TypeUtils.getRawType() throws a
> NullPointerException on Wildcard GenericArrayType.
> > +Throw IllegalArgumentException instead of InternalError in the
> builder package.
> >  
> >  Add GitHub coverage.yml.
> >  Add EnumUtils.getEnumSystemProperty(...).
> > diff --git
> a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> > index 38c69e613..3d411bb15 100644
> > ---
> a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> > +++
> b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> > @@ -97,19 +97,37 @@ import org.apache.commons.lang3.ObjectUtils;
> >  public class CompareToBuilder implements Builder {
> >
> >  /**
> > - * Current state of the comparison as appended fields are checked.
> > - */
> > -private int comparison;
> > -
> > -/**
> > - * Constructor for CompareToBuilder.
> > + * Appends to {@code builder} the comparison of {@code lhs}
> > + * to {@code rhs} using the fields defined in {@code clazz}.
> >   *
> > - * Starts off assuming that the objects are equal. Multiple
> calls are
> > - * then made to the various append methods, followed by a call to
> > - * {@link #toComparison} to get the result.
> > + * @param lhs  left-hand object
> > + * @param rhs  right-hand object
> > + * @param clazz  {@link Class} that defines fields to be compared
> > + * @param builder  {@link CompareToBuilder} to append to
> > + * @param useTransients  whether to compare transient fields
> > + * @param excludeFields  fields to exclude
> >   */
> > -public CompareToBuilder() {
> > -comparison = 0;
> > +private static void reflectionAppend(
> > +final Object lhs,
> > +final Object rhs,
> > +final Class clazz,
> > +final CompareToBuilder builder,
> > +final boolean useTransients,
> > +final String[] excludeFields) {
> > +
> > +final Field[] fields = clazz.getDeclaredFields();
> > +AccessibleObject.setAccessible(fields, true);
> > +for (int i = 0; i < fields.length && builder.comparison == 0;
> i++) {
> > +final Field field = fields[i];
> > +if (!ArrayUtils.contains(excludeFields, field.getName())
> > +&& !field.getName().contains("$")
> > +&& (useTransients ||
> !Modifier.isTransient(field.getModifiers()))
> > +&& !Modifier.isStatic(field.getModifiers())) {
> > +// IllegalAccessException can't happen. Would get a
> Security exception instead.
> > +// Throw a runtime exception in case the impossible
> happens.
> > +builder.append(Reflection.getUnchecked(field, lhs),
> Reflection.getUnchecked(field, rhs));
> > +}
> > +}
> >  }
> >
> >  /**
> > @@ -183,10 +201,11 @@ public class CompareToBuilder implements
> Builder {
> >   *
> >   * 
> >   * Static fields will not be compared
> > - * If {@code compareTransients} is {@code true},
> > + * If the {@code compareTransients} is {@code true},
> >   * compares transient members.  Otherwise ignores them, 

Re: [commons-lang] 04/04: Throw IllegalArgumentException instead of InternalError in the builder package

2023-07-12 Thread Gilles Sadowski
Hi.

Le mer. 12 juil. 2023 à 14:44,  a écrit :
>
> This is an automated email from the ASF dual-hosted git repository.
>
> ggregory pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-lang.git
>
> commit 2e3feda04337baa483bc26b66f238161dc6c97ac
> Author: Gary Gregory 
> AuthorDate: Wed Jul 12 08:44:38 2023 -0400
>
> Throw IllegalArgumentException instead of InternalError in the builder
> package

The diff below contains a bunch of (formatting ?) changes that
have nothing to do with this commit message.

Regards,
Gilles

> ---
>  src/changes/changes.xml|   1 +
>  .../commons/lang3/builder/CompareToBuilder.java| 752 
> ++---
>  .../commons/lang3/builder/EqualsBuilder.java   |  20 +-
>  .../commons/lang3/builder/HashCodeBuilder.java |   9 +-
>  .../apache/commons/lang3/builder/Reflection.java   |  44 ++
>  .../lang3/builder/ReflectionDiffBuilder.java   |   7 +-
>  .../lang3/builder/ReflectionToStringBuilder.java   |  14 +-
>  7 files changed, 434 insertions(+), 413 deletions(-)
>
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index 26d7be48c..da3522029 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -123,6 +123,7 @@ The  type attribute can be add,update,fix,remove.
>  Update Javadoc for the insert methods in ArrayUtils #1078.
>  Deprecate ExceptionUtils.ExceptionUtils().
>  TypeUtils.getRawType() throws a NullPointerException on 
> Wildcard GenericArrayType.
> +Throw IllegalArgumentException instead of InternalError in the 
> builder package.
>  
>  Add GitHub coverage.yml.
>  Add EnumUtils.getEnumSystemProperty(...).
> diff --git 
> a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java 
> b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> index 38c69e613..3d411bb15 100644
> --- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> +++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
> @@ -97,19 +97,37 @@ import org.apache.commons.lang3.ObjectUtils;
>  public class CompareToBuilder implements Builder {
>
>  /**
> - * Current state of the comparison as appended fields are checked.
> - */
> -private int comparison;
> -
> -/**
> - * Constructor for CompareToBuilder.
> + * Appends to {@code builder} the comparison of {@code lhs}
> + * to {@code rhs} using the fields defined in {@code clazz}.
>   *
> - * Starts off assuming that the objects are equal. Multiple calls are
> - * then made to the various append methods, followed by a call to
> - * {@link #toComparison} to get the result.
> + * @param lhs  left-hand object
> + * @param rhs  right-hand object
> + * @param clazz  {@link Class} that defines fields to be compared
> + * @param builder  {@link CompareToBuilder} to append to
> + * @param useTransients  whether to compare transient fields
> + * @param excludeFields  fields to exclude
>   */
> -public CompareToBuilder() {
> -comparison = 0;
> +private static void reflectionAppend(
> +final Object lhs,
> +final Object rhs,
> +final Class clazz,
> +final CompareToBuilder builder,
> +final boolean useTransients,
> +final String[] excludeFields) {
> +
> +final Field[] fields = clazz.getDeclaredFields();
> +AccessibleObject.setAccessible(fields, true);
> +for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
> +final Field field = fields[i];
> +if (!ArrayUtils.contains(excludeFields, field.getName())
> +&& !field.getName().contains("$")
> +&& (useTransients || 
> !Modifier.isTransient(field.getModifiers()))
> +&& !Modifier.isStatic(field.getModifiers())) {
> +// IllegalAccessException can't happen. Would get a Security 
> exception instead.
> +// Throw a runtime exception in case the impossible happens.
> +builder.append(Reflection.getUnchecked(field, lhs), 
> Reflection.getUnchecked(field, rhs));
> +}
> +}
>  }
>
>  /**
> @@ -183,10 +201,11 @@ public class CompareToBuilder implements 
> Builder {
>   *
>   * 
>   * Static fields will not be compared
> - * If {@code compareTransients} is {@code true},
> + * If the {@code compareTransients} is {@code true},
>   * compares transient members.  Otherwise ignores them, as they
>   * are likely derived fields.
> - * Superclass fields will be compared
> + * Compares superclass fields up to and including {@code 
> reflectUpToClass}.
> + * If {@code reflectUpToClass} is {@code null}, compares all 
> superclass fields.
>   * 
>   *
>   * If both {@code lhs} and {@code rhs} are {@code null},
> @@ -194,17 +213,41 @@ public class