Bubble Sort with tests
Your code looks generally OK in my book (i.e. not being that rusty ;-))

A few pointers though:


Generally keep variable scope as low as possible. T temp and boolean swapped can be declared at the place where they are needed initially.
Though I see the idea of multiplying with 1 or -1, the expression looks too "magic" for me. As Comparators have a reversed() method these days, I recommend to use that.


Putting this advice to use:

public static &lt;T&gt; T[] bubbleSort(T[] data, Comparator&lt;T&gt; comparator, boolean ascending) {
    Objects.requireNonNull(data);
    int len = data.length;
    if (len &lt;= 0) return data;
    Comparator&lt;T&gt; actualComparator = ascending ? comparator : comparator.reversed();

    for (int i = 0; i &lt; len - 1; i++) {
        boolean swapped  = false;
        for (int j = 0; j &lt; len - 1 - i; j++) {
            if (actualComparator.compare(data[j], data[j + 1]) &gt; 0) {
                T temp = data[j];
                data[j] = data[j + 1];
                data[j + 1] = temp;
                swapped = true;
            }
        }
        if (!swapped) break;
    }
    return data;
}