Skip to content

Commit 3286fee

Browse files
Code cleanup and modernization:
- Removed unreachable and redundant if statements - Fixed potential memory leak by replacing ThreadLocal.set(null) with remove() - Replaced instanceof checks with Class.isInstance() - Modernized list creation using List.of(...) instead of Collections.unmodifiableList(Arrays.asList(...))
1 parent a2e40f1 commit 3286fee

File tree

27 files changed

+265
-303
lines changed

27 files changed

+265
-303
lines changed

querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/CollQueryFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Number apply(Number num1, Number num2) {
8585
}
8686
};
8787

88-
private static final List<Object> nullList = Collections.singletonList((Object) null);
88+
private static final List<Object> nullList = Collections.singletonList(null);
8989

9090
@SuppressWarnings("unused")
9191
public static boolean equals(Object o1, Object o2) {
@@ -231,7 +231,7 @@ public static Number aggregate(
231231
} else if (aggregator == Ops.AggOps.COUNT_AGG) {
232232
return (long) source.size();
233233
} else if (aggregator == Ops.AggOps.COUNT_DISTINCT_AGG) {
234-
if (!Set.class.isInstance(source)) {
234+
if (!(source instanceof Set)) {
235235
source = new HashSet<>(source);
236236
}
237237
return (long) source.size();

querydsl-libraries/querydsl-collections/src/main/java/com/querydsl/collections/CollQuerySerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public Void visit(SubQueryExpression<?> expr, Void context) {
164164
}
165165

166166
private void visitCast(Operator operator, Expression<?> source, Class<?> targetType) {
167-
if (Number.class.isAssignableFrom(source.getType()) && !Constant.class.isInstance(source)) {
167+
if (Number.class.isAssignableFrom(source.getType()) && !(source instanceof Constant)) {
168168
append("new ").append(source.getType().getSimpleName()).append("(");
169169
handle(source);
170170
append(")");

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/DefaultQueryMetadata.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.io.Serial;
3232
import java.util.ArrayList;
3333
import java.util.Collections;
34-
import java.util.HashSet;
3534
import java.util.LinkedHashMap;
3635
import java.util.LinkedHashSet;
3736
import java.util.List;
@@ -252,12 +251,7 @@ public List<JoinExpression> getJoins() {
252251
return Collections.unmodifiableList(joins);
253252
} else {
254253
List<JoinExpression> j = new ArrayList<>(joins);
255-
j.add(
256-
new JoinExpression(
257-
joinType,
258-
joinTarget,
259-
joinCondition,
260-
Collections.unmodifiableSet(new HashSet<>(joinFlags))));
254+
j.add(new JoinExpression(joinType, joinTarget, joinCondition, Set.copyOf(joinFlags)));
261255
return j;
262256
}
263257
}

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/AliasFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public <A extends Expression<?>> A getCurrentAndReset() {
165165

166166
/** Reset the thread bound expression to null */
167167
public void reset() {
168-
current.set(null);
168+
current.remove();
169169
}
170170

171171
/**

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/ExpressionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public static Expression<String> likeToRegex(Expression<String> expr, boolean ma
558558
if (matchStartAndEnd && !like.endsWith("%")) {
559559
rv.append('$');
560560
}
561-
if (!like.equals(rv.toString())) {
561+
if (!like.contentEquals(rv)) {
562562
return ConstantImpl.create(rv.toString());
563563
}
564564
} else if (expr instanceof Operation<?> o) {

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/CollectionPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected CollectionPath(Class<? super E> type, Class<Q> queryType, PathMetadata
6060
@SuppressWarnings("unchecked")
6161
protected CollectionPath(
6262
Class<? super E> type, Class<Q> queryType, PathMetadata metadata, PathInits inits) {
63-
super(new ParameterizedPathImpl<>((Class) Collection.class, metadata, type), inits);
63+
super(new ParameterizedPathImpl<>(Collection.class, metadata, type), inits);
6464
this.elementType = (Class<E>) type;
6565
this.queryType = queryType;
6666
this.pathMixin = (PathImpl<Collection<E>>) mixin;

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/Expressions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static <T> Expression<T> constant(T value) {
165165
@SuppressWarnings({"unchecked", "rawtypes"})
166166
public static <D> SimpleExpression<D> constantAs(D source, Path<D> alias) {
167167
if (source == null) {
168-
return as((Expression) nullExpression(), alias);
168+
return as(nullExpression(), alias);
169169
} else {
170170
return as(ConstantImpl.create(source), alias);
171171
}

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/ListPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected ListPath(Class<? super E> elementType, Class<Q> queryType, PathMetadat
6565
@SuppressWarnings("unchecked")
6666
protected ListPath(
6767
Class<? super E> elementType, Class<Q> queryType, PathMetadata metadata, PathInits inits) {
68-
super(new ParameterizedPathImpl<>((Class) List.class, metadata, elementType), inits);
68+
super(new ParameterizedPathImpl<>(List.class, metadata, elementType), inits);
6969
this.elementType = (Class<E>) elementType;
7070
this.queryType = queryType;
7171
this.pathMixin = (PathImpl<List<E>>) mixin;

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/MapPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected MapPath(
7171
Class<? super V> valueType,
7272
Class<E> queryType,
7373
PathMetadata metadata) {
74-
super(new ParameterizedPathImpl<>((Class) Map.class, metadata, keyType, valueType));
74+
super(new ParameterizedPathImpl<>(Map.class, metadata, keyType, valueType));
7575
this.keyType = (Class<K>) keyType;
7676
this.valueType = (Class<V>) valueType;
7777
this.queryType = queryType;

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/dsl/SetPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected SetPath(Class<? super E> type, Class<Q> queryType, PathMetadata metada
5959
@SuppressWarnings("unchecked")
6060
protected SetPath(
6161
Class<? super E> type, Class<Q> queryType, PathMetadata metadata, PathInits inits) {
62-
super(new ParameterizedPathImpl<>((Class) Set.class, metadata, type), inits);
62+
super(new ParameterizedPathImpl<>(Set.class, metadata, type), inits);
6363
this.elementType = (Class<E>) type;
6464
this.queryType = queryType;
6565
this.pathMixin = (PathImpl<Set<E>>) mixin;

0 commit comments

Comments
 (0)