Skip to content

Commit 9fc09fc

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 9fc09fc

File tree

22 files changed

+260
-298
lines changed

22 files changed

+260
-298
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/util/BeanMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,9 @@ private void initialise() {
564564
}
565565

566566
/**
567-
* Called during a successful {@link #put(Object,Object)} operation. Default implementation does
568-
* nothing. Override to be notified of property changes in the bean caused by this map.
567+
* Called during a successful {@link #put(String, Object)} (Object,Object)} operation. Default
568+
* implementation does nothing. Override to be notified of property changes in the bean caused by
569+
* this map.
569570
*
570571
* @param key the name of the property that changed
571572
* @param oldValue the old value for that property

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static <T> List<T> unmodifiableList(List<T> list) {
108108
return switch (list.size()) {
109109
case 0 -> Collections.emptyList();
110110
case 1 -> Collections.singletonList(list.get(0));
111-
default -> Collections.unmodifiableList(new ArrayList<>(list));
111+
default -> List.copyOf(list);
112112
};
113113
}
114114

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/Conversions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ private static boolean needsConstantRemoval(Expression<?> expr) {
7171

7272
private static boolean needsNumberConversion(Expression<?> expr) {
7373
expr = ExpressionUtils.extract(expr);
74-
return Number.class.isAssignableFrom(expr.getType()) && !Path.class.isInstance(expr);
74+
return Number.class.isAssignableFrom(expr.getType()) && !(expr instanceof Path);
7575
}
7676

7777
private static boolean isEntityPathAndNeedsWrapping(Expression<?> expr) {
7878
if ((expr instanceof Path && expr.getType().isAnnotationPresent(Entity.class))
79-
|| (expr instanceof EntityPath && !RelationalPath.class.isInstance(expr))) {
79+
|| (expr instanceof EntityPath && !(expr instanceof RelationalPath))) {
8080
Path<?> path = (Path<?>) expr;
8181
if (path.getMetadata().getParent() == null) {
8282
return true;

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPAExpressions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static <U extends BeanPath<? extends T>, T> U treat(
144144
public static <A extends Comparable<? super A>> ComparableExpression<A> avg(
145145
CollectionExpression<?, A> col) {
146146
return Expressions.comparableOperation(
147-
(Class) col.getParameter(0), Ops.QuantOps.AVG_IN_COL, (Expression<?>) col);
147+
(Class) col.getParameter(0), Ops.QuantOps.AVG_IN_COL, col);
148148
}
149149

150150
/**
@@ -156,7 +156,7 @@ public static <A extends Comparable<? super A>> ComparableExpression<A> avg(
156156
public static <A extends Comparable<? super A>> ComparableExpression<A> max(
157157
CollectionExpression<?, A> left) {
158158
return Expressions.comparableOperation(
159-
(Class) left.getParameter(0), Ops.QuantOps.MAX_IN_COL, (Expression<?>) left);
159+
(Class) left.getParameter(0), Ops.QuantOps.MAX_IN_COL, left);
160160
}
161161

162162
/**
@@ -168,7 +168,7 @@ public static <A extends Comparable<? super A>> ComparableExpression<A> max(
168168
public static <A extends Comparable<? super A>> ComparableExpression<A> min(
169169
CollectionExpression<?, A> left) {
170170
return Expressions.comparableOperation(
171-
(Class) left.getParameter(0), Ops.QuantOps.MIN_IN_COL, (Expression<?>) left);
171+
(Class) left.getParameter(0), Ops.QuantOps.MIN_IN_COL, left);
172172
}
173173

174174
/**

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public void serializeForInsert(
320320
first = false;
321321
}
322322
append(")");
323-
} else if (inserts != null && inserts.entrySet().size() > 0) {
323+
} else if (inserts != null && !inserts.isEmpty()) {
324324
first = true;
325325
for (Map.Entry<Path<?>, Expression<?>> entry : inserts.entrySet()) {
326326
if (!first) {

0 commit comments

Comments
 (0)