diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3941f0fda..bfed99f85 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ + Fix deprecation warnings EnumUtils.generateBitVector needs a "? extends" Validate: add inclusiveBetween and exclusiveBetween overloads for primitive types New RandomUtils class diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index c1edcb39a..434aff7db 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -207,6 +207,11 @@ public class ObjectUtils { return obj == null ? 0 : obj.hashCode(); } + @Override + public String toString() { + return super.toString(); + } + /** *

Gets the hash code for multiple objects.

* diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index e9a331afc..2a1c2f843 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4039,7 +4039,9 @@ public class StringUtils { } final Object first = iterator.next(); if (!iterator.hasNext()) { - return ObjectUtils.toString(first); + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 + String result = ObjectUtils.toString(first); + return result; } // two or more elements @@ -4083,7 +4085,9 @@ public class StringUtils { } final Object first = iterator.next(); if (!iterator.hasNext()) { - return ObjectUtils.toString(first); + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 + final String result = ObjectUtils.toString(first); + return result; } // two or more elements diff --git a/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java index 62a715eb9..0d15711ac 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java @@ -101,6 +101,7 @@ public class ConstantInitializer implements ConcurrentInitializer { * @param obj the object to compare to * @return a flag whether the objects are equal */ + @SuppressWarnings( "deprecation" ) // ObjectUtils.equals(Object, Object) has been deprecated in 3.2 @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index 865d6099d..2dbc30fc4 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -203,6 +203,7 @@ public class TypeUtils { /** * {@inheritDoc} */ + @SuppressWarnings( "deprecation" ) // ObjectUtils.hashCode(Object) has been deprecated in 3.2 @Override public int hashCode() { int result = 71 << 4; @@ -1566,6 +1567,7 @@ public class TypeUtils { * @return boolean * @since 3.2 */ + @SuppressWarnings( "deprecation" ) // ObjectUtils.equals(Object, Object) has been deprecated in 3.2 public static boolean equals(Type t1, Type t2) { if (ObjectUtils.equals(t1, t2)) { return true; diff --git a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java index 59c51e93f..1d1c5a5a4 100644 --- a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java +++ b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java @@ -289,6 +289,7 @@ public class ExtendedMessageFormat extends MessageFormat { * * @return the hashcode */ + @SuppressWarnings( "deprecation" ) // ObjectUtils.hashCode(Object) has been deprecated in 3.2 @Override public int hashCode() { int result = super.hashCode(); diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java index d20cdfe97..926ff80de 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java +++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java @@ -1128,12 +1128,13 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @param separator the separator to use, null means no separator * @return this, to enable chaining */ - public StrBuilder appendWithSeparators(final Object[] array, String separator) { + public StrBuilder appendWithSeparators(final Object[] array, final String separator) { if (array != null && array.length > 0) { - separator = ObjectUtils.toString(separator); + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 + final String sep = ObjectUtils.toString(separator); append(array[0]); for (int i = 1; i < array.length; i++) { - append(separator); + append(sep); append(array[i]); } } @@ -1150,14 +1151,15 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @param separator the separator to use, null means no separator * @return this, to enable chaining */ - public StrBuilder appendWithSeparators(final Iterable iterable, String separator) { + public StrBuilder appendWithSeparators(final Iterable iterable, final String separator) { if (iterable != null) { - separator = ObjectUtils.toString(separator); + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 + final String sep = ObjectUtils.toString(separator); final Iterator it = iterable.iterator(); while (it.hasNext()) { append(it.next()); if (it.hasNext()) { - append(separator); + append(sep); } } } @@ -1174,13 +1176,14 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @param separator the separator to use, null means no separator * @return this, to enable chaining */ - public StrBuilder appendWithSeparators(final Iterator it, String separator) { + public StrBuilder appendWithSeparators(final Iterator it, final String separator) { if (it != null) { - separator = ObjectUtils.toString(separator); + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 + final String sep = ObjectUtils.toString(separator); while (it.hasNext()) { append(it.next()); if (it.hasNext()) { - append(separator); + append(sep); } } } diff --git a/src/main/java/org/apache/commons/lang3/tuple/Pair.java b/src/main/java/org/apache/commons/lang3/tuple/Pair.java index 36d97a326..b3f4e5976 100644 --- a/src/main/java/org/apache/commons/lang3/tuple/Pair.java +++ b/src/main/java/org/apache/commons/lang3/tuple/Pair.java @@ -125,6 +125,7 @@ public abstract class Pair implements Map.Entry, Comparable implements Comparable>, Se * @param obj the object to compare to, null returns false * @return true if the elements of the triple are equal */ + @SuppressWarnings( "deprecation" ) // ObjectUtils.equals(Object, Object) has been deprecated in 3.2 @Override public boolean equals(final Object obj) { if (obj == this) { diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index df86eeb9c..2df5ae86e 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -280,12 +280,14 @@ public class ObjectUtilsTest { } } + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 @Test public void testToString_Object() { assertEquals("", ObjectUtils.toString((Object) null) ); assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE) ); } - + + @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 @Test public void testToString_ObjectString() { assertEquals(BAR, ObjectUtils.toString((Object) null, BAR) );