ImmutablesSortedSetComparator
ERROR
LikelyError
Summary
SortedSet
properties of a@Value.Immutable
or@Value.Modifiable
type must be annotated with@Value.NaturalOrder
or@Value.ReverseOrder
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ImmutablesSortedSetComparator")
to the enclosing element.Disable this pattern completely by adding
-Xep:ImmutablesSortedSetComparator:OFF
as compiler argument. Learn more.
Samples
Replacement
Shows the difference in example code before and after the bug pattern is applied.
import com.google.common.collect.ImmutableSortedSet;
import java.util.SortedSet;
import org.immutables.value.Value;
@Value.Immutable
abstract class A {
+ @Value.NaturalOrder
abstract ImmutableSortedSet<String> sortedSet();
@Value.Modifiable
interface B {
+ @Value.NaturalOrder
SortedSet<String> sortedSet();
}
}
import com.google.common.collect.ImmutableSortedSet;
import org.springframework.beans.factory.annotation.Value;
class MySpringService {
MySpringService(@Value("${someProperty}") String prop) {}
;
@org.immutables.value.Value.Immutable
interface A {
+ @org.immutables.value.Value.NaturalOrder
ImmutableSortedSet<String> sortedSet();
}
}
Identification
Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains:
comment is placed above any violating line.
import com.google.common.collect.ContiguousSet;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.immutables.value.Value;
interface A {
@Value.Immutable
interface ImmutableInterface {
Set<String> set();
// BUG: Diagnostic contains:
SortedSet<String> sortedSet();
@Value.NaturalOrder
SortedSet<String> sortedSet2();
}
@Value.Modifiable
interface ModifiableInterfaceWithDefaults {
@Value.Default
default Set<Integer> set() {
return new TreeSet<>();
}
@Value.Default
// BUG: Diagnostic contains:
default NavigableSet<Integer> navigableSet() {
return new TreeSet<>();
}
@Value.Default
@Value.ReverseOrder
default NavigableSet<Integer> navigableSet2() {
return new TreeSet<>();
}
default NavigableSet<Integer> nonPropertyNavigableSet() {
return new TreeSet<>();
}
}
interface NonImmutablesInterface {
SortedSet<String> sortedSet();
}
@Value.Immutable
abstract class AbstractImmutableWithDefaults {
@Value.Default
ImmutableSet<Integer> immutableSet() {
return ImmutableSet.of();
}
@Value.Default
// BUG: Diagnostic contains:
ImmutableSortedSet<String> immutableSortedSet() {
return ImmutableSortedSet.of();
}
@Value.Default
@Value.NaturalOrder
ImmutableSortedSet<String> immutableSortedSet2() {
return ImmutableSortedSet.of();
}
ImmutableSortedSet<String> nonPropertyImmutableSortedSet() {
return ImmutableSortedSet.of();
}
}
@Value.Modifiable
abstract class AbstractModifiable {
abstract ImmutableSet<Integer> immutableSet();
// BUG: Diagnostic contains:
abstract ContiguousSet<Integer> contiguousSet();
@Value.ReverseOrder
abstract ContiguousSet<Integer> contiguousSet2();
}
abstract class AbstractNonImmutables {
abstract SortedSet<Integer> sortedSet();
}
}