Skip to content

Commit 2a44064

Browse files
authored
Work around/suppress around 95 warnings produced on JDK-17 with -Xlint:all (assertj#2648)
Work around/suppress around 95 warnings produced on JDK-17 with -Xlint flag enabled. Fix a couple of warnings dotted around in tests to do with unchecked operations Fix incorrect javadoc reference in Floats_AssertLessThanOrEqualTo_test
1 parent 92a85ef commit 2a44064

12 files changed

+99
-32
lines changed

src/main/java/org/assertj/core/api/AbstractMapAssert.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ public SELF containsExactlyInAnyOrderEntriesOf(Map<? extends K, ? extends V> map
685685
return containsOnly(toEntries(map));
686686
}
687687

688+
@SuppressWarnings("unchecked")
688689
private Map.Entry<? extends K, ? extends V>[] toEntries(Map<? extends K, ? extends V> map) {
689690
return map.entrySet().toArray(new Map.Entry[0]);
690691
}

src/main/java/org/assertj/core/api/AbstractObjectArrayAssert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
* @author Lovro Pandzic
9191
*/
9292
// suppression of deprecation works in Eclipse to hide warning for the deprecated classes in the imports
93-
@SuppressWarnings("deprecation")
93+
// IntelliJ thinks this is redundant when it is not.
94+
@SuppressWarnings({"deprecation", "RedundantSuppression"})
9495
public abstract class AbstractObjectArrayAssert<SELF extends AbstractObjectArrayAssert<SELF, ELEMENT>, ELEMENT> extends
9596
AbstractAssert<SELF, ELEMENT[]>
9697
implements IndexedObjectEnumerableAssert<AbstractObjectArrayAssert<SELF, ELEMENT>, ELEMENT>,

src/main/java/org/assertj/core/api/AbstractOptionalAssert.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
* @author Nicolai Parlog
4545
* @author Grzegorz Piwowarek
4646
*/
47-
@SuppressWarnings("deprecation")
47+
// Deprecation is raised by JDK-17. IntelliJ thinks this is redundant when it is not.
48+
@SuppressWarnings({"deprecation", "RedundantSuppression"})
4849
public abstract class AbstractOptionalAssert<SELF extends AbstractOptionalAssert<SELF, VALUE>, VALUE> extends
4950
AbstractAssert<SELF, Optional<VALUE>> {
5051

@@ -278,6 +279,7 @@ public SELF containsInstanceOf(Class<?> clazz) {
278279
*/
279280
@Deprecated
280281
@CheckReturnValue
282+
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"})
281283
public SELF usingFieldByFieldValueComparator() {
282284
return usingValueComparator(new FieldByFieldComparator());
283285
}

src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@
7070
import org.assertj.core.util.introspection.IntrospectionError;
7171

7272
// suppression of deprecation works in Eclipse to hide warning for the deprecated classes in the imports
73-
@SuppressWarnings("deprecation")
73+
// Deprecation is raised by JDK-17. IntelliJ thinks this is redundant when it is not.
74+
@SuppressWarnings({"deprecation", "RedundantSuppression"})
7475
public class AtomicReferenceArrayAssert<T>
7576
extends AbstractAssert<AtomicReferenceArrayAssert<T>, AtomicReferenceArray<T>>
7677
implements IndexedObjectEnumerableAssert<AtomicReferenceArrayAssert<T>, T>,
7778
ArraySortedAssert<AtomicReferenceArrayAssert<T>, T> {
7879

79-
private T[] array;
80+
private final T[] array;
8081
@VisibleForTesting
8182
ObjectArrays arrays = ObjectArrays.instance();
8283
@VisibleForTesting
8384
Iterables iterables = Iterables.instance();
8485

8586
private TypeComparators comparatorsByType;
86-
private Map<String, Comparator<?>> comparatorsForElementPropertyOrFieldNames = new TreeMap<>();
87+
private final Map<String, Comparator<?>> comparatorsForElementPropertyOrFieldNames = new TreeMap<>();
8788
private TypeComparators comparatorsForElementPropertyOrFieldTypes;
8889

8990
public AtomicReferenceArrayAssert(AtomicReferenceArray<T> actual) {

src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public interface InstanceOfAssertFactories {
8989
*
9090
* @see #PREDICATE
9191
*/
92-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
92+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
93+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
94+
// IntelliJ can warn that this is redundant when it is not.
9395
static <T> InstanceOfAssertFactory<Predicate, PredicateAssert<T>> predicate(Class<T> type) {
9496
return new InstanceOfAssertFactory<>(Predicate.class, Assertions::<T> assertThat);
9597
}
@@ -129,7 +131,9 @@ static <T> InstanceOfAssertFactory<Predicate, PredicateAssert<T>> predicate(Clas
129131
*
130132
* @see #COMPLETABLE_FUTURE
131133
*/
132-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
134+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
135+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
136+
// IntelliJ can warn that this is redundant when it is not.
133137
static <RESULT> InstanceOfAssertFactory<CompletableFuture, CompletableFutureAssert<RESULT>> completableFuture(Class<RESULT> resultType) {
134138
return new InstanceOfAssertFactory<>(CompletableFuture.class, Assertions::<RESULT> assertThat);
135139
}
@@ -151,7 +155,9 @@ static <RESULT> InstanceOfAssertFactory<CompletableFuture, CompletableFutureAsse
151155
*
152156
* @see #COMPLETION_STAGE
153157
*/
154-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
158+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
159+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
160+
// IntelliJ can warn that this is redundant when it is not.
155161
static <RESULT> InstanceOfAssertFactory<CompletionStage, CompletableFutureAssert<RESULT>> completionStage(Class<RESULT> resultType) {
156162
return new InstanceOfAssertFactory<>(CompletionStage.class, Assertions::<RESULT> assertThat);
157163
}
@@ -173,7 +179,9 @@ static <RESULT> InstanceOfAssertFactory<CompletionStage, CompletableFutureAssert
173179
*
174180
* @see #OPTIONAL
175181
*/
176-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
182+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
183+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
184+
// IntelliJ can warn that this is redundant when it is not.
177185
static <VALUE> InstanceOfAssertFactory<Optional, OptionalAssert<VALUE>> optional(Class<VALUE> resultType) {
178186
return new InstanceOfAssertFactory<>(Optional.class, Assertions::<VALUE> assertThat);
179187
}
@@ -338,7 +346,9 @@ static <VALUE> InstanceOfAssertFactory<Optional, OptionalAssert<VALUE>> optional
338346
*
339347
* @see #FUTURE
340348
*/
341-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
349+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
350+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
351+
// IntelliJ can warn that this is redundant when it is not.
342352
static <RESULT> InstanceOfAssertFactory<Future, FutureAssert<RESULT>> future(Class<RESULT> resultType) {
343353
return new InstanceOfAssertFactory<>(Future.class, Assertions::<RESULT> assertThat);
344354
}
@@ -574,7 +584,9 @@ static <ELEMENT> InstanceOfAssertFactory<ELEMENT[][], Object2DArrayAssert<ELEMEN
574584
*
575585
* @see #ATOMIC_INTEGER_FIELD_UPDATER
576586
*/
577-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
587+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
588+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
589+
// IntelliJ can warn that this is redundant when it is not.
578590
static <OBJECT> InstanceOfAssertFactory<AtomicIntegerFieldUpdater, AtomicIntegerFieldUpdaterAssert<OBJECT>> atomicIntegerFieldUpdater(Class<OBJECT> objectType) {
579591
return new InstanceOfAssertFactory<>(AtomicIntegerFieldUpdater.class, Assertions::<OBJECT> assertThat);
580592
}
@@ -614,7 +626,9 @@ static <OBJECT> InstanceOfAssertFactory<AtomicIntegerFieldUpdater, AtomicInteger
614626
*
615627
* @see #ATOMIC_LONG_FIELD_UPDATER
616628
*/
617-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
629+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
630+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
631+
// IntelliJ can warn that this is redundant when it is not.
618632
static <OBJECT> InstanceOfAssertFactory<AtomicLongFieldUpdater, AtomicLongFieldUpdaterAssert<OBJECT>> atomicLongFieldUpdater(Class<OBJECT> objectType) {
619633
return new InstanceOfAssertFactory<>(AtomicLongFieldUpdater.class, Assertions::<OBJECT> assertThat);
620634
}
@@ -636,7 +650,9 @@ static <OBJECT> InstanceOfAssertFactory<AtomicLongFieldUpdater, AtomicLongFieldU
636650
*
637651
* @see #ATOMIC_REFERENCE
638652
*/
639-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
653+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
654+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
655+
// IntelliJ can warn that this is redundant when it is not.
640656
static <VALUE> InstanceOfAssertFactory<AtomicReference, AtomicReferenceAssert<VALUE>> atomicReference(Class<VALUE> valueType) {
641657
return new InstanceOfAssertFactory<>(AtomicReference.class, Assertions::<VALUE> assertThat);
642658
}
@@ -658,7 +674,9 @@ static <VALUE> InstanceOfAssertFactory<AtomicReference, AtomicReferenceAssert<VA
658674
*
659675
* @see #ATOMIC_REFERENCE_ARRAY
660676
*/
661-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
677+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
678+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
679+
// IntelliJ can warn that this is redundant when it is not.
662680
static <ELEMENT> InstanceOfAssertFactory<AtomicReferenceArray, AtomicReferenceArrayAssert<ELEMENT>> atomicReferenceArray(Class<ELEMENT> elementType) {
663681
return new InstanceOfAssertFactory<>(AtomicReferenceArray.class, Assertions::<ELEMENT> assertThat);
664682
}
@@ -683,7 +701,9 @@ static <ELEMENT> InstanceOfAssertFactory<AtomicReferenceArray, AtomicReferenceAr
683701
*
684702
* @see #ATOMIC_REFERENCE_FIELD_UPDATER
685703
*/
686-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
704+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
705+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
706+
// IntelliJ can warn that this is redundant when it is not.
687707
static <FIELD, OBJECT> InstanceOfAssertFactory<AtomicReferenceFieldUpdater, AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT>> atomicReferenceFieldUpdater(Class<FIELD> fieldType,
688708
Class<OBJECT> objectType) {
689709
return new InstanceOfAssertFactory<>(AtomicReferenceFieldUpdater.class, Assertions::<FIELD, OBJECT> assertThat);
@@ -706,7 +726,9 @@ static <FIELD, OBJECT> InstanceOfAssertFactory<AtomicReferenceFieldUpdater, Atom
706726
*
707727
* @see #ATOMIC_MARKABLE_REFERENCE
708728
*/
709-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
729+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
730+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
731+
// IntelliJ can warn that this is redundant when it is not.
710732
static <VALUE> InstanceOfAssertFactory<AtomicMarkableReference, AtomicMarkableReferenceAssert<VALUE>> atomicMarkableReference(Class<VALUE> valueType) {
711733
return new InstanceOfAssertFactory<>(AtomicMarkableReference.class, Assertions::<VALUE> assertThat);
712734
}
@@ -728,7 +750,9 @@ static <VALUE> InstanceOfAssertFactory<AtomicMarkableReference, AtomicMarkableRe
728750
*
729751
* @see #ATOMIC_STAMPED_REFERENCE
730752
*/
731-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
753+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
754+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
755+
// IntelliJ can warn that this is redundant when it is not.
732756
static <VALUE> InstanceOfAssertFactory<AtomicStampedReference, AtomicStampedReferenceAssert<VALUE>> atomicStampedReference(Class<VALUE> valueType) {
733757
return new InstanceOfAssertFactory<>(AtomicStampedReference.class, Assertions::<VALUE> assertThat);
734758
}
@@ -794,7 +818,9 @@ static <T extends Throwable> InstanceOfAssertFactory<T, AbstractThrowableAssert<
794818
*
795819
* @see #ITERABLE
796820
*/
797-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
821+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
822+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
823+
// IntelliJ can warn that this is redundant when it is not.
798824
static <ELEMENT> InstanceOfAssertFactory<Iterable, IterableAssert<ELEMENT>> iterable(Class<ELEMENT> elementType) {
799825
return new InstanceOfAssertFactory<>(Iterable.class, Assertions::<ELEMENT> assertThat);
800826
}
@@ -816,7 +842,9 @@ static <ELEMENT> InstanceOfAssertFactory<Iterable, IterableAssert<ELEMENT>> iter
816842
*
817843
* @see #ITERATOR
818844
*/
819-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
845+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
846+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
847+
// IntelliJ can warn that this is redundant when it is not.
820848
static <ELEMENT> InstanceOfAssertFactory<Iterator, IteratorAssert<ELEMENT>> iterator(Class<ELEMENT> elementType) {
821849
return new InstanceOfAssertFactory<>(Iterator.class, Assertions::<ELEMENT> assertThat);
822850
}
@@ -840,7 +868,9 @@ static <ELEMENT> InstanceOfAssertFactory<Iterator, IteratorAssert<ELEMENT>> iter
840868
* @see #COLLECTION
841869
* @since 3.21.0
842870
*/
843-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
871+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
872+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
873+
// IntelliJ can warn that this is redundant when it is not.
844874
static <E> InstanceOfAssertFactory<Collection, AbstractCollectionAssert<?, Collection<? extends E>, E, ObjectAssert<E>>> collection(Class<E> elementType) {
845875
return new InstanceOfAssertFactory<>(Collection.class, Assertions::<E> assertThat);
846876
}
@@ -862,7 +892,9 @@ static <E> InstanceOfAssertFactory<Collection, AbstractCollectionAssert<?, Colle
862892
*
863893
* @see #LIST
864894
*/
865-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
895+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
896+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
897+
// IntelliJ can warn that this is redundant when it is not.
866898
static <ELEMENT> InstanceOfAssertFactory<List, ListAssert<ELEMENT>> list(Class<ELEMENT> elementType) {
867899
return new InstanceOfAssertFactory<>(List.class, Assertions::<ELEMENT> assertThat);
868900
}
@@ -884,7 +916,9 @@ static <ELEMENT> InstanceOfAssertFactory<List, ListAssert<ELEMENT>> list(Class<E
884916
*
885917
* @see #STREAM
886918
*/
887-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
919+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
920+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
921+
// IntelliJ can warn that this is redundant when it is not.
888922
static <ELEMENT> InstanceOfAssertFactory<Stream, ListAssert<ELEMENT>> stream(Class<ELEMENT> elementType) {
889923
return new InstanceOfAssertFactory<>(Stream.class, Assertions::<ELEMENT> assertThat);
890924
}
@@ -930,7 +964,9 @@ static <ELEMENT> InstanceOfAssertFactory<Stream, ListAssert<ELEMENT>> stream(Cla
930964
*
931965
* @see #SPLITERATOR
932966
*/
933-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
967+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
968+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
969+
// IntelliJ can warn that this is redundant when it is not.
934970
static <ELEMENT> InstanceOfAssertFactory<Spliterator, SpliteratorAssert<ELEMENT>> spliterator(Class<ELEMENT> elementType) {
935971
return new InstanceOfAssertFactory<>(Spliterator.class, Assertions::<ELEMENT> assertThat);
936972
}
@@ -954,7 +990,9 @@ static <ELEMENT> InstanceOfAssertFactory<Spliterator, SpliteratorAssert<ELEMENT>
954990
*
955991
* @see #MAP
956992
*/
957-
@SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference
993+
@SuppressWarnings({"rawtypes", "unused", "unchecked", "RedundantSuppression"})
994+
// rawtypes+unchecked: using Class instance, unused: parameter needed for type inference.
995+
// IntelliJ can warn that this is redundant when it is not.
958996
static <K, V> InstanceOfAssertFactory<Map, MapAssert<K, V>> map(Class<K> keyType, Class<V> valueType) {
959997
return new InstanceOfAssertFactory<>(Map.class, Assertions::<K, V> assertThat);
960998
}

src/main/java/org/assertj/core/api/Java6BDDAssertions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
*/
5656
@Deprecated
5757
@CheckReturnValue
58+
// Deprecation is raised by JDK-17. IntelliJ thinks this is redundant when it is not.
59+
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation", "RedundantSuppression"})
5860
public class Java6BDDAssertions {
5961

6062
/**

src/main/java/org/assertj/core/api/ListAssert.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ private AssertionError actualDoesNotStartWithSequence(AssertionInfo info, Object
220220
.failure(info, shouldStartWith("Stream under test", sequence, iterables.getComparisonStrategy()));
221221
}
222222

223-
@SuppressWarnings("rawtypes")
224-
private ListFromStream asListFromStream() {
225-
return (ListFromStream) actual;
223+
@SuppressWarnings("unchecked")
224+
private ListFromStream<ELEMENT, Stream<ELEMENT>> asListFromStream() {
225+
return (ListFromStream<ELEMENT, Stream<ELEMENT>>) actual;
226226
}
227227

228228
@VisibleForTesting

0 commit comments

Comments
 (0)