public static <T extends Comparable<T>> void sortOptionallyComparables(@Nonnull List<T> toReturn) {
        try {
            Collections.sort(toReturn);
        } catch (IllegalArgumentException e) {
            // catch possible sorting misbehaviour
            if (!e.getMessage().contains("Comparison method violates its general contract!")) {
                throw e;
            }
            // otherwise print a warning and leave the list unsorted
        }
    }
public static < T extends Comparable < T > > void sortOptionallyComparables ( @ Nonnull List < T > toReturn ) { try { Collections . sort ( toReturn ) ; } catch ( IllegalArgumentException e ) { if ( ! e . getMessage ( ) . contains ( "Comparison method violates its general contract!" ) ) { throw e ; } } }
Sort the input collection; if the ordering is unstable and an error is
thrown (due to the use of TimSort in JDK 1.7 and newer), catch it and
leave the collection unsorted. NOTE: use this method if ordering is
desirable but not necessary.

@param <T>
list type
@param toReturn
list to sort