Repository: commons-lang
Updated Branches:
  refs/heads/master d6644e4fb -> 96c8ea2fb


add @SafeVarargs to some methods with vararg parameters to suppress "Type 
safety: Potential heap pollution via varargs parameter array" warnings


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/96c8ea2f
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/96c8ea2f
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/96c8ea2f

Branch: refs/heads/master
Commit: 96c8ea2fb3719e2f6e3d7a4d7b46718f26515a86
Parents: d6644e4
Author: pascalschumacher <pascalschumac...@gmx.net>
Authored: Sun Oct 23 22:09:43 2016 +0200
Committer: pascalschumacher <pascalschumac...@gmx.net>
Committed: Sun Oct 23 22:09:43 2016 +0200

----------------------------------------------------------------------
 src/main/java/org/apache/commons/lang3/ArrayUtils.java     | 9 +++++----
 src/main/java/org/apache/commons/lang3/EnumUtils.java      | 2 ++
 src/main/java/org/apache/commons/lang3/ObjectUtils.java    | 9 +++++++--
 src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java | 1 +
 4 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/96c8ea2f/src/main/java/org/apache/commons/lang3/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java 
b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 85149ef..f8ae695 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -301,6 +301,7 @@ public class ArrayUtils {
      * @return the array, not null unless a null array is passed in
      * @since  3.0
      */
+    @SafeVarargs
     public static <T> T[] toArray(final T... items) {
         return items;
     }
@@ -5058,6 +5059,7 @@ public class ArrayUtils {
      * @since 2.1
      * @throws IllegalArgumentException if the array types are incompatible
      */
+    @SafeVarargs
     public static <T> T[] addAll(final T[] array1, final T... array2) {
         if (array1 == null) {
             return clone(array2);
@@ -5066,8 +5068,7 @@ public class ArrayUtils {
         }
         final Class<?> type1 = array1.getClass().getComponentType();
         @SuppressWarnings("unchecked") // OK, because array is of type T
-        final
-        T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + 
array2.length);
+        final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + 
array2.length);
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
         try {
             System.arraycopy(array2, 0, joinedArray, array1.length, 
array2.length);
@@ -6607,6 +6608,7 @@ public class ArrayUtils {
      *         earliest-encountered occurrences of the specified elements.
      * @since 3.0.1
      */
+    @SafeVarargs
     public static <T> T[] removeElements(final T[] array, final T... values) {
         if (isEmpty(array) || isEmpty(values)) {
             return clone(array);
@@ -6632,8 +6634,7 @@ public class ArrayUtils {
             }
         }
         @SuppressWarnings("unchecked") // removeAll() always creates an array 
of the same type as its input
-        final
-        T[] result = (T[]) removeAll(array, toRemove);
+        final T[] result = (T[]) removeAll(array, toRemove);
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/96c8ea2f/src/main/java/org/apache/commons/lang3/EnumUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/EnumUtils.java 
b/src/main/java/org/apache/commons/lang3/EnumUtils.java
index 8280bf8..d6bcdc0 100644
--- a/src/main/java/org/apache/commons/lang3/EnumUtils.java
+++ b/src/main/java/org/apache/commons/lang3/EnumUtils.java
@@ -198,6 +198,7 @@ public class EnumUtils {
      * @since 3.0.1
      * @see #generateBitVectors(Class, Iterable)
      */
+    @SafeVarargs
     public static <E extends Enum<E>> long generateBitVector(final Class<E> 
enumClass, final E... values) {
         Validate.noNullElements(values);
         return generateBitVector(enumClass, Arrays.<E> asList(values));
@@ -219,6 +220,7 @@ public class EnumUtils {
      * @throws IllegalArgumentException if {@code enumClass} is not an enum 
class, or if any {@code values} {@code null}
      * @since 3.2
      */
+    @SafeVarargs
     public static <E extends Enum<E>> long[] generateBitVectors(final Class<E> 
enumClass, final E... values) {
         asEnum(enumClass);
         Validate.noNullElements(values);

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/96c8ea2f/src/main/java/org/apache/commons/lang3/ObjectUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java 
b/src/main/java/org/apache/commons/lang3/ObjectUtils.java
index 84b4b10..f951e7d 100644
--- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java
@@ -117,6 +117,7 @@ public class ObjectUtils {
      *  or {@code null} if there are no non-null values
      * @since 3.0
      */
+    @SafeVarargs
     public static <T> T firstNonNull(final T... values) {
         if (values != null) {
             for (final T val : values) {
@@ -498,6 +499,7 @@ public class ObjectUtils {
      *   <li>If all the comparables are null, null is returned.
      *  </ul>
      */
+    @SafeVarargs
     public static <T extends Comparable<? super T>> T min(final T... values) {
         T result = null;
         if (values != null) {
@@ -523,6 +525,7 @@ public class ObjectUtils {
      *   <li>If all the comparables are null, null is returned.
      *  </ul>
      */
+    @SafeVarargs
     public static <T extends Comparable<? super T>> T max(final T... values) {
         T result = null;
         if (values != null) {
@@ -583,14 +586,14 @@ public class ObjectUtils {
      * @throws IllegalArgumentException if items is empty or contains {@code 
null} values
      * @since 3.0.1
      */
+    @SafeVarargs
     public static <T extends Comparable<? super T>> T median(final T... items) 
{
         Validate.notEmpty(items);
         Validate.noNullElements(items);
         final TreeSet<T> sort = new TreeSet<>();
         Collections.addAll(sort, items);
         @SuppressWarnings("unchecked") //we know all items added were T 
instances
-        final
-        T result = (T) sort.toArray()[(sort.size() - 1) / 2];
+        final T result = (T) sort.toArray()[(sort.size() - 1) / 2];
         return result;
     }
 
@@ -605,6 +608,7 @@ public class ObjectUtils {
      * @throws IllegalArgumentException if items is empty or contains {@code 
null} values
      * @since 3.0.1
      */
+    @SafeVarargs
     public static <T> T median(final Comparator<T> comparator, final T... 
items) {
         Validate.notEmpty(items, "null/empty items");
         Validate.noNullElements(items);
@@ -627,6 +631,7 @@ public class ObjectUtils {
      * @return most populous T, {@code null} if non-unique or no items supplied
      * @since 3.0.1
      */
+    @SafeVarargs
     public static <T> T mode(final T... items) {
         if (ArrayUtils.isNotEmpty(items)) {
             final HashMap<T, MutableInt> occurrences = new 
HashMap<>(items.length);

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/96c8ea2f/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index 7b2f578..0cb5530 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -218,6 +218,7 @@ public class ArrayUtilsTest  {
         assertEquals(0, array.length);
     }
 
+    @SafeVarargs
     private static <T> T[] toArrayPropagatingType(final T... items)
     {
         return ArrayUtils.toArray(items);

Reply via email to