Skip to content

Commit 055d4a8

Browse files
refactor: Common static analysis issues
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.CommonStaticAnalysis?organizationId=TmV0ZmxpeCArIFNwcmluZw%3D%3D Co-authored-by: Moderne <[email protected]>
1 parent 88011e6 commit 055d4a8

File tree

176 files changed

+496
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+496
-547
lines changed

Diff for: src/main/java/org/springframework/data/annotation/AccessType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
Type value();
4141

4242
enum Type {
43-
FIELD, PROPERTY;
43+
FIELD, PROPERTY
4444
}
4545
}

Diff for: src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private ManagedTypes resolveManagedTypes(RegisteredBean registeredBean) {
8080
ValueHolder indexedArgumentValue = beanDefinition.getConstructorArgumentValues().getIndexedArgumentValue(0, null);
8181
Object value = indexedArgumentValue.getValue();
8282

83-
if (value instanceof Collection<?> values && values.stream().allMatch(it -> it instanceof Class)) {
83+
if (value instanceof Collection<?> values && values.stream().allMatch(Class.class::isInstance)) {
8484
return ManagedTypes.fromIterable((Collection<Class<?>>) values);
8585
}
8686
}

Diff for: src/main/java/org/springframework/data/auditing/Auditor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Christoph Strobl
2727
* @since 2.4
2828
*/
29-
class Auditor<T> {
29+
final class Auditor<T> {
3030

3131
private static final Auditor NONE = new Auditor(null) {
3232

@@ -105,10 +105,12 @@ public String toString() {
105105

106106
@Override
107107
public boolean equals(Object o) {
108-
if (this == o)
108+
if (this == o) {
109109
return true;
110-
if (o == null || getClass() != o.getClass())
110+
}
111+
if (o == null || getClass() != o.getClass()) {
111112
return false;
113+
}
112114

113115
Auditor<?> auditor = (Auditor<?>) o;
114116

Diff for: src/main/java/org/springframework/data/convert/CustomConversions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ protected enum ConverterOrigin {
668668
* @author Oliver Gierke
669669
* @author Mark Paluch
670670
*/
671-
private static class ConverterRegistration {
671+
private static final class ConverterRegistration {
672672

673673
private final Object converter;
674674
private final ConvertiblePair convertiblePair;
@@ -744,7 +744,7 @@ Object getConverter() {
744744
*
745745
* @author Oliver Gierke
746746
*/
747-
public static class StoreConversions {
747+
public static final class StoreConversions {
748748

749749
public static final StoreConversions NONE = StoreConversions.of(SimpleTypeHolder.DEFAULT, Collections.emptyList());
750750

Diff for: src/main/java/org/springframework/data/convert/JMoleculesConverters.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public static Collection<Object> getConvertersToRegister() {
5454

5555
List<Object> converters = new ArrayList<>();
5656

57-
Supplier<ConversionService> conversionService = (Supplier<ConversionService>) () -> DefaultConversionService
58-
.getSharedInstance();
57+
Supplier<ConversionService> conversionService = (Supplier<ConversionService>) DefaultConversionService::getSharedInstance;
5958

6059
IdentifierToPrimitivesConverter toPrimitives = new IdentifierToPrimitivesConverter(conversionService);
6160
PrimitivesToIdentifierConverter toIdentifier = new PrimitivesToIdentifierConverter(conversionService);

Diff for: src/main/java/org/springframework/data/convert/SimplePropertyValueConverterRegistry.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ public Key(Class<?> type, String path) {
104104

105105
@Override
106106
public boolean equals(Object o) {
107-
if (this == o)
107+
if (this == o) {
108108
return true;
109-
if (o == null || getClass() != o.getClass())
109+
}
110+
if (o == null || getClass() != o.getClass()) {
110111
return false;
112+
}
111113

112114
Key key = (Key) o;
113115

Diff for: src/main/java/org/springframework/data/domain/AbstractAggregateRoot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class AbstractAggregateRoot<A extends AbstractAggregateRoot<A>> {
3737

38-
private transient final @Transient List<Object> domainEvents = new ArrayList<>();
38+
private final transient @Transient List<Object> domainEvents = new ArrayList<>();
3939

4040
/**
4141
* Registers the given event object for publication on a call to a Spring Data repository's save or delete methods.

Diff for: src/main/java/org/springframework/data/domain/ExampleMatcher.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ interface MatcherConfigurer<T> {
280280
*/
281281
class GenericPropertyMatcher {
282282

283-
@Nullable StringMatcher stringMatcher = null;
284-
@Nullable Boolean ignoreCase = null;
283+
@Nullable StringMatcher stringMatcher;
284+
@Nullable Boolean ignoreCase;
285285
PropertyValueTransformer valueTransformer = NoOpPropertyValueTransformer.INSTANCE;
286286

287287
/**
@@ -451,8 +451,9 @@ public boolean equals(Object o) {
451451
return false;
452452
}
453453

454-
if (stringMatcher != that.stringMatcher)
454+
if (stringMatcher != that.stringMatcher) {
455455
return false;
456+
}
456457

457458
if (!ObjectUtils.nullSafeEquals(ignoreCase, that.ignoreCase)) {
458459
return false;
@@ -582,7 +583,7 @@ enum StringMatcher {
582583
/**
583584
* Treats strings as regular expression patterns
584585
*/
585-
REGEX;
586+
REGEX
586587
}
587588

588589
/**
@@ -741,8 +742,9 @@ public boolean equals(Object o) {
741742
return false;
742743
}
743744

744-
if (stringMatcher != that.stringMatcher)
745+
if (stringMatcher != that.stringMatcher) {
745746
return false;
747+
}
746748

747749
if (!ObjectUtils.nullSafeEquals(ignoreCase, that.ignoreCase)) {
748750
return false;
@@ -833,6 +835,6 @@ public int hashCode() {
833835
* @see ExampleMatcher#isAllMatching()
834836
*/
835837
enum MatchMode {
836-
ALL, ANY;
838+
ALL, ANY
837839
}
838840
}

Diff for: src/main/java/org/springframework/data/domain/Range.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,9 @@ public boolean equals(Object o) {
457457
return true;
458458
}
459459

460-
if (inclusive != bound.inclusive)
460+
if (inclusive != bound.inclusive) {
461461
return false;
462+
}
462463

463464
return ObjectUtils.nullSafeEquals(value, bound.value);
464465
}

Diff for: src/main/java/org/springframework/data/domain/SliceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public String toString() {
7474
String contentType = "UNKNOWN";
7575
List<T> content = getContent();
7676

77-
if (content.size() > 0) {
77+
if (!content.isEmpty()) {
7878
contentType = content.get(0).getClass().getName();
7979
}
8080

Diff for: src/main/java/org/springframework/data/domain/Sort.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public Sort and(Sort sort) {
194194

195195
Assert.notNull(sort, "Sort must not be null");
196196

197-
List<Order> these = new ArrayList<Order>(this.toList());
197+
List<Order> these = new ArrayList<>(this.toList());
198198

199199
for (Order order : sort) {
200200
these.add(order);
@@ -378,7 +378,7 @@ public enum NullHandling {
378378
/**
379379
* A hint to the used data store to order entries with null values after non null entries.
380380
*/
381-
NULLS_LAST;
381+
NULLS_LAST
382382
}
383383

384384
/**
@@ -677,7 +677,7 @@ public String toString() {
677677
* @since 2.2
678678
* @soundtrack The Intersphere - Linger (The Grand Delusion)
679679
*/
680-
public static class TypedSort<T> extends Sort {
680+
public static final class TypedSort<T> extends Sort {
681681

682682
private static final long serialVersionUID = -3550403511206745880L;
683683

Diff for: src/main/java/org/springframework/data/domain/WindowImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ public Iterator<T> iterator() {
9494

9595
@Override
9696
public boolean equals(Object o) {
97-
if (this == o)
97+
if (this == o) {
9898
return true;
99-
if (o == null || getClass() != o.getClass())
99+
}
100+
if (o == null || getClass() != o.getClass()) {
100101
return false;
102+
}
101103
WindowImpl<?> that = (WindowImpl<?>) o;
102104
return ObjectUtils.nullSafeEquals(items, that.items)
103105
&& ObjectUtils.nullSafeEquals(positionFunction, that.positionFunction)

Diff for: src/main/java/org/springframework/data/geo/GeoModule.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public GeoModule() {
4949
}
5050

5151
@JsonIgnoreProperties("unit")
52-
static abstract class DistanceMixin {
52+
abstract static class DistanceMixin {
5353

5454
DistanceMixin(@JsonProperty("value") double value,
5555
@JsonProperty("metric") @JsonDeserialize(as = Metrics.class) Metric metic) {}
@@ -58,19 +58,19 @@ static abstract class DistanceMixin {
5858
abstract double getNormalizedValue();
5959
}
6060

61-
static abstract class PointMixin {
61+
abstract static class PointMixin {
6262
PointMixin(@JsonProperty("x") double x, @JsonProperty("y") double y) {}
6363
}
6464

65-
static abstract class CircleMixin {
65+
abstract static class CircleMixin {
6666
CircleMixin(@JsonProperty("center") Point center, @JsonProperty("radius") Distance radius) {}
6767
}
6868

69-
static abstract class BoxMixin {
69+
abstract static class BoxMixin {
7070
BoxMixin(@JsonProperty("first") Point first, @JsonProperty("second") Point point) {}
7171
}
7272

73-
static abstract class PolygonMixin {
73+
abstract static class PolygonMixin {
7474
PolygonMixin(@JsonProperty("points") List<Point> points) {}
7575
}
7676
}

Diff for: src/main/java/org/springframework/data/geo/Point.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ public boolean equals(@Nullable Object obj) {
109109
return false;
110110
}
111111

112-
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) {
113-
return false;
114-
}
115-
116-
return true;
112+
return !(Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y));
117113
}
118114

119115
@Override

Diff for: src/main/java/org/springframework/data/history/RevisionSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @since 1.13
2929
* @soundtrack Benny Greb's Moving Parts - Soulfood (Live)
3030
*/
31-
public class RevisionSort extends Sort {
31+
public final class RevisionSort extends Sort {
3232

3333
private static final long serialVersionUID = 618238321589063537L;
3434

Diff for: src/main/java/org/springframework/data/history/Revisions.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* @author Oliver Gierke
3232
* @author Christoph Strobl
3333
*/
34-
public class Revisions<N extends Number & Comparable<N>, T> implements Streamable<Revision<N, T>> {
34+
public final class Revisions<N extends Number & Comparable<N>, T> implements Streamable<Revision<N, T>> {
3535

36-
private final Comparator<Revision<N, T>> NATURAL_ORDER = Comparator.naturalOrder();
36+
private final Comparator<Revision<N, T>> naturalOrder = Comparator.naturalOrder();
3737

3838
private final List<Revision<N, T>> revisions;
3939
private final boolean latestLast;
@@ -59,7 +59,7 @@ private Revisions(List<? extends Revision<N, T>> revisions, boolean latestLast)
5959
Assert.notNull(revisions, "Revisions must not be null");
6060

6161
this.revisions = revisions.stream()//
62-
.sorted(latestLast ? NATURAL_ORDER : NATURAL_ORDER.reversed())//
62+
.sorted(latestLast ? naturalOrder : naturalOrder.reversed())//
6363
.collect(StreamUtils.toUnmodifiableList());
6464

6565
this.latestLast = latestLast;

Diff for: src/main/java/org/springframework/data/mapping/AccessOptions.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public <T> GetOptions registerHandler(PersistentProperty<?> property, Class<T> t
186186
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
187187
.format("Cannot register a property handler for %s on a property of type %s", type, property.getType()));
188188

189-
Function<Object, T> caster = (Function<Object, T>) it -> type.cast(it);
189+
Function<Object, T> caster = (Function<Object, T>) type::cast;
190190

191191
return registerHandler(property, caster.andThen(handler));
192192
}
@@ -260,7 +260,7 @@ public enum SetNulls {
260260
/**
261261
* Silently skip the attempt to set the value.
262262
*/
263-
SKIP;
263+
SKIP
264264
}
265265

266266
/**
@@ -279,7 +279,7 @@ public enum Propagation {
279279
* Propagate the setting of values when encountering a collection or map value and set it on all collection or map
280280
* members.
281281
*/
282-
PROPAGATE;
282+
PROPAGATE
283283
}
284284

285285
private static final SetOptions DEFAULT = new SetOptions();
@@ -356,11 +356,7 @@ public boolean propagate(@Nullable PersistentProperty<?> property) {
356356
return false;
357357
}
358358

359-
if (property.isMap() && mapPropagation.equals(Propagation.SKIP)) {
360-
return false;
361-
}
362-
363-
return true;
359+
return !(property.isMap() && mapPropagation.equals(Propagation.SKIP));
364360
}
365361
}
366362
}

Diff for: src/main/java/org/springframework/data/mapping/PropertyPath.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public PropertyPath nested(String path) {
258258
@Override
259259
public Iterator<PropertyPath> iterator() {
260260

261-
return new Iterator<PropertyPath>() {
261+
return new Iterator<>() {
262262

263263
private @Nullable PropertyPath current = PropertyPath.this;
264264

Diff for: src/main/java/org/springframework/data/mapping/callback/EntityCallbackInvoker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static boolean matchesClassCastMessage(String exceptionMessage, Class<?> eventCl
5454
}
5555

5656
// On Java 18, the message is "IllegalArgumentException: argument type mismatch"
57-
if (exceptionMessage.equals("argument type mismatch")) {
57+
if ("argument type mismatch".equals(exceptionMessage)) {
5858
return true;
5959
}
6060

Diff for: src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
100100

101101
private static final Log LOGGER = LogFactory.getLog(MappingContext.class);
102102

103-
private final Optional<E> NONE = Optional.empty();
103+
private final Optional<E> none = Optional.empty();
104104
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
105105
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
106106
private final PersistentPropertyPathFactory<E, P> persistentPropertyPathFactory;
@@ -111,7 +111,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
111111

112112
private ManagedTypes managedTypes = ManagedTypes.empty();
113113

114-
private boolean strict = false;
114+
private boolean strict;
115115
private SimpleTypeHolder simpleTypeHolder = SimpleTypeHolder.DEFAULT;
116116

117117
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
@@ -305,7 +305,7 @@ public E getPersistentEntity(TypeInformation<?> type) {
305305

306306
try {
307307
write.lock();
308-
persistentEntities.put(type, NONE);
308+
persistentEntities.put(type, none);
309309
} finally {
310310
write.unlock();
311311
}
@@ -758,7 +758,7 @@ private Class<?> getPropertyType(PersistentProperty<?> persistentProperty) {
758758
*
759759
* @author Oliver Gierke
760760
*/
761-
static enum PersistentPropertyFilter implements FieldFilter {
761+
enum PersistentPropertyFilter implements FieldFilter {
762762

763763
INSTANCE;
764764

@@ -844,11 +844,7 @@ public boolean matches(String name, Class<?> type) {
844844
return false;
845845
}
846846

847-
if ((typeName != null) && !type.getName().equals(typeName)) {
848-
return false;
849-
}
850-
851-
return true;
847+
return !((typeName != null) && !type.getName().equals(typeName));
852848
}
853849
}
854850
}

0 commit comments

Comments
 (0)