Skip to content

Commit 81f6097

Browse files
committed
Apply null annotations in org.hibernate.query.sqm.tree
1 parent 26a89c2 commit 81f6097

File tree

320 files changed

+2756
-2262
lines changed

Some content is hidden

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

320 files changed

+2756
-2262
lines changed

checkerstubs/jakarta.persistence.astub

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package jakarta.persistence;
44

55
import org.checkerframework.checker.nullness.qual.Nullable;
6+
import org.checkerframework.checker.nullness.qual.NonNull;
67

78
public interface AttributeConverter<X,Y> {
89
public @Nullable Y convertToDatabaseColumn(@Nullable X attribute);
@@ -20,9 +21,10 @@ public interface EntityManagerFactory extends AutoCloseable {
2021
public interface EntityTransaction {
2122
@Nullable Integer getTimeout();
2223
}
23-
public interface Parameter {
24-
public @Nullable String getName();
25-
public @Nullable Integer getPosition();
24+
public interface Parameter<T> {
25+
@Nullable String getName();
26+
@Nullable Integer getPosition();
27+
@Nullable Class<T> getParameterType();
2628
}
2729
public interface PersistenceUnitUtil extends PersistenceUtil {
2830
public @Nullable Object getIdentifier(Object entity);
@@ -86,9 +88,9 @@ public interface CommonAbstractCriteria {
8688
}
8789
public interface AbstractQuery<T> extends CommonAbstractCriteria {
8890
AbstractQuery<T> where(@Nullable Expression<Boolean> restriction);
89-
AbstractQuery<T> where(@Nullable Predicate... restrictions);
91+
AbstractQuery<T> where(Predicate @Nullable... restrictions);
9092
AbstractQuery<T> having(@Nullable Expression<Boolean> restriction);
91-
AbstractQuery<T> having(@Nullable Predicate... restrictions);
93+
AbstractQuery<T> having(Predicate @Nullable... restrictions);
9294
@Nullable Selection<T> getSelection();
9395
@Nullable Predicate getGroupRestriction();
9496
}
@@ -99,12 +101,18 @@ public interface CriteriaUpdate<T> extends CommonAbstractCriteria {
99101
}
100102
public interface Subquery<T> extends AbstractQuery<T>, Expression<T> {
101103
Subquery<T> where(@Nullable Expression<Boolean> restriction);
102-
Subquery<T> where(@Nullable Predicate... restrictions);
104+
Subquery<T> where(Predicate @Nullable... restrictions);
103105
Subquery<T> having(@Nullable Expression<Boolean> restriction);
104-
Subquery<T> having(@Nullable Predicate... restrictions);
106+
Subquery<T> having(Predicate @Nullable... restrictions);
105107
@Nullable Expression<T> getSelection();
106108
}
107109
public interface CriteriaBuilder {
110+
interface In<T> extends Predicate {
111+
In<T> value(@NonNull T value);
112+
}
113+
interface Coalesce<T> extends Expression<T> {
114+
Coalesce<T> value(@Nullable T value);
115+
}
108116
public static interface SimpleCase<C,R> extends Expression<R> {
109117
SimpleCase<C, R> when(C condition, @Nullable R result);
110118
SimpleCase<C, R> when(Expression<? extends C> condition, @Nullable R result);
@@ -117,26 +125,28 @@ public interface CriteriaBuilder {
117125
}
118126
public interface Join<Z, X> extends From<Z, X> {
119127
Join<Z, X> on(@Nullable Expression<Boolean> restriction);
120-
Join<Z, X> on(@Nullable Predicate... restrictions);
128+
Join<Z, X> on(Predicate @Nullable... restrictions);
121129
@Nullable Predicate getOn();
130+
@Nullable From<?, Z> getParent();
131+
@Nullable Attribute<? super Z, ?> getAttribute();
122132
}
123133
public interface SetJoin<Z,E> extends PluralJoin<Z, Set<E>, E> {
124134
SetJoin<Z, E> on(@Nullable Expression<Boolean> restriction);
125-
SetJoin<Z, E> on(@Nullable Predicate... restrictions);
135+
SetJoin<Z, E> on(Predicate @Nullable... restrictions);
126136
}
127137
public interface ListJoin<Z,E> extends PluralJoin<Z, List<E>, E> {
128138
ListJoin<Z, E> on(@Nullable Expression<Boolean> restriction);
129-
ListJoin<Z, E> on(@Nullable Predicate... restrictions);
139+
ListJoin<Z, E> on(Predicate @Nullable... restrictions);
130140
}
131141
public interface MapJoin<Z,K,V> extends PluralJoin<Z, Map<K,V>, V> {
132142
MapJoin<Z,K,V> on(@Nullable Expression<Boolean> restriction);
133-
MapJoin<Z,K,V> on(@Nullable Predicate... restrictions);
143+
MapJoin<Z,K,V> on(Predicate @Nullable... restrictions);
134144
}
135145
public interface Path<X> extends Expression<X> {
136146
// CteRoot etc.
137147
@Nullable Bindable<X> getModel();
138148
@Nullable Path<?> getParentPath();
139-
MapJoin<Z,K,V> on(@Nullable Predicate... restrictions);
149+
MapJoin<Z,K,V> on(Predicate @Nullable... restrictions);
140150
}
141151

142152
package jakarta.persistence.metamodel;

checkerstubs/jboss.logging.astub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ public interface BasicLogger {
1111
public interface Logger {
1212
void tracev(String format, @Nullable Object param1);
1313
void tracef(String format, @Nullable Object param1);
14+
void tracev(String format, @Nullable Object param1, @Nullable Object param2);
15+
void tracef(String format, @Nullable Object param1, @Nullable Object param2);
16+
void warnv(String format, @Nullable Object param1);
17+
void warnf(String format, @Nullable Object param1);
18+
void warnv(String format, @Nullable Object param1, @Nullable Object param2);
19+
void warnf(String format, @Nullable Object param1, @Nullable Object param2);
20+
void debugv(String format, @Nullable Object param1);
21+
void debugf(String format, @Nullable Object param1);
22+
void debugv(String format, @Nullable Object param1, @Nullable Object param2);
23+
void debugf(String format, @Nullable Object param1, @Nullable Object param2);
1424
}

hibernate-core/src/main/java/org/hibernate/QueryException.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.hibernate;
66

7+
import org.checkerframework.checker.nullness.qual.Nullable;
8+
79
/**
810
* A problem occurred translating a Hibernate query to SQL due to illegal query
911
* syntax, an operation which is not well-typed, an unresolvable reference to
@@ -23,7 +25,7 @@
2325
* @see org.hibernate.query.SyntaxException
2426
*/
2527
public class QueryException extends HibernateException {
26-
private final String queryString;
28+
private final @Nullable String queryString;
2729

2830
/**
2931
* Constructs a {@code QueryException} using the specified exception message.
@@ -58,7 +60,7 @@ public QueryException(String message, Exception cause) {
5860
* @param message A message explaining the exception condition
5961
* @param queryString The query being evaluated when the exception occurred
6062
*/
61-
public QueryException(String message, String queryString) {
63+
public QueryException(String message, @Nullable String queryString) {
6264
this( message, queryString, null );
6365
}
6466

@@ -69,7 +71,7 @@ public QueryException(String message, String queryString) {
6971
* @param queryString The query being evaluated when the exception occurred
7072
* @param cause The underlying cause
7173
*/
72-
public QueryException(String message, String queryString, Exception cause) {
74+
public QueryException(String message, @Nullable String queryString, Exception cause) {
7375
super( message, cause );
7476
this.queryString = queryString;
7577
}
@@ -93,7 +95,7 @@ public QueryException(Exception cause) {
9395
*
9496
* @return The query string
9597
*/
96-
public String getQueryString() {
98+
public @Nullable String getQueryString() {
9799
return queryString;
98100
}
99101

hibernate-core/src/main/java/org/hibernate/dialect/function/DateTruncEmulation.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
*/
4040
public class DateTruncEmulation extends AbstractSqmFunctionDescriptor implements FunctionRenderer {
4141
protected final String toDateFunction;
42-
private final SqmFormat sqmFormat;
4342

4443
protected DateTruncEmulation(String toDateFunction, TypeConfiguration typeConfiguration) {
4544
super(
@@ -49,7 +48,6 @@ protected DateTruncEmulation(String toDateFunction, TypeConfiguration typeConfig
4948
StandardFunctionArgumentTypeResolvers.invariant( typeConfiguration, TEMPORAL, TEMPORAL_UNIT )
5049
);
5150
this.toDateFunction = toDateFunction;
52-
this.sqmFormat = new SqmFormat( "yyyy-MM-dd HH:mm:ss", typeConfiguration.getBasicTypeForJavaType( String.class ), null );
5351
}
5452

5553
@Override
@@ -106,7 +104,7 @@ protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(
106104
final var datetime = arguments.get( 0 );
107105
final var formatExpression =
108106
queryEngine.getSqmFunctionRegistry()
109-
.findFunctionDescriptor( "format" )
107+
.getFunctionDescriptor( "format" )
110108
.generateSqmExpression(
111109
asList(
112110
datetime,
@@ -119,7 +117,7 @@ protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(
119117
if ( literal != null ) {
120118
formattedDatetime =
121119
queryEngine.getSqmFunctionRegistry()
122-
.findFunctionDescriptor( "concat" )
120+
.getFunctionDescriptor( "concat" )
123121
.generateSqmExpression(
124122
asList(
125123
formatExpression,
@@ -137,7 +135,7 @@ protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(
137135
this,
138136
this,
139137
// the first argument is needed for SybaseDateTruncEmulation
140-
asList( datetime, formattedDatetime, sqmFormat ),
138+
asList( datetime, formattedDatetime, new SqmFormat( "yyyy-MM-dd HH:mm:ss", nodeBuilder.getStringType(), nodeBuilder ) ),
141139
impliedResultType,
142140
null,
143141
getReturnTypeResolver(),

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ArrayViaElementArgumentReturnTypeResolver.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.metamodel.mapping.MappingModelExpressible;
1212
import org.hibernate.metamodel.model.domain.DomainType;
1313
import org.hibernate.metamodel.model.domain.ReturnableType;
14+
import org.hibernate.query.sqm.SqmBindableType;
1415
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
1516
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
1617
import org.hibernate.query.sqm.tree.SqmTypedNode;
@@ -61,22 +62,28 @@ else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
6162
}
6263
if ( elementIndex == -1 ) {
6364
for ( SqmTypedNode<?> argument : arguments ) {
64-
final DomainType<?> sqmType = argument.getExpressible().getSqmType();
65+
final SqmBindableType<?> expressible = argument.getExpressible();
66+
if ( expressible != null ) {
67+
final DomainType<?> sqmType = expressible.getSqmType();
68+
if ( sqmType instanceof ReturnableType<?> ) {
69+
return list
70+
? DdlTypeHelper.resolveListType( sqmType, typeConfiguration )
71+
: DdlTypeHelper.resolveArrayType( sqmType, typeConfiguration );
72+
}
73+
}
74+
}
75+
}
76+
else {
77+
final SqmBindableType<?> expressible = arguments.get( elementIndex ).getExpressible();
78+
if ( expressible != null ) {
79+
final DomainType<?> sqmType = expressible.getSqmType();
6580
if ( sqmType instanceof ReturnableType<?> ) {
6681
return list
6782
? DdlTypeHelper.resolveListType( sqmType, typeConfiguration )
6883
: DdlTypeHelper.resolveArrayType( sqmType, typeConfiguration );
6984
}
7085
}
7186
}
72-
else {
73-
final DomainType<?> sqmType = arguments.get( elementIndex ).getExpressible().getSqmType();
74-
if ( sqmType instanceof ReturnableType<?> ) {
75-
return list
76-
? DdlTypeHelper.resolveListType( sqmType, typeConfiguration )
77-
: DdlTypeHelper.resolveArrayType( sqmType, typeConfiguration );
78-
}
79-
}
8087
return null;
8188
}
8289

hibernate-core/src/main/java/org/hibernate/engine/query/spi/AbstractParameterDescriptor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.engine.query.spi;
66

7+
import org.checkerframework.checker.nullness.qual.Nullable;
78
import org.hibernate.Incubating;
89
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
910
import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl;
@@ -19,39 +20,38 @@
1920
public abstract class AbstractParameterDescriptor<T> implements QueryParameter<T> {
2021
private final int[] sourceLocations;
2122

22-
private BindableType<T> expectedType;
23+
private @Nullable BindableType<T> expectedType;
2324

24-
public AbstractParameterDescriptor(int[] sourceLocations, BindableType<T> expectedType) {
25+
public AbstractParameterDescriptor(int[] sourceLocations, @Nullable BindableType<T> expectedType) {
2526
this.sourceLocations = sourceLocations;
2627
this.expectedType = expectedType;
2728
}
2829

2930
@Override
30-
public String getName() {
31+
public @Nullable String getName() {
3132
return null;
3233
}
3334

3435
@Override
35-
public Integer getPosition() {
36+
public @Nullable Integer getPosition() {
3637
return null;
3738
}
3839

3940
@Override
40-
public Class<T> getParameterType() {
41+
public @Nullable Class<T> getParameterType() {
4142
return expectedType == null ? null : expectedType.getJavaType();
4243
}
4344

4445
@Override
45-
public BindableType<T> getHibernateType() {
46+
public @Nullable BindableType<T> getHibernateType() {
4647
return getExpectedType();
4748
}
4849

49-
50-
public BindableType<T> getExpectedType() {
50+
public @Nullable BindableType<T> getExpectedType() {
5151
return expectedType;
5252
}
5353

54-
public void resetExpectedType(BindableType<T> expectedType) {
54+
public void resetExpectedType(@Nullable BindableType<T> expectedType) {
5555
this.expectedType = expectedType;
5656
}
5757

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ void missingArguments(
328328
@LogMessage(level = WARN)
329329
@Message(value = "The query [%s] updates an immutable entity: %s",
330330
id = 487)
331-
void immutableEntityUpdateQuery(String sourceQuery, String querySpaces);
331+
void immutableEntityUpdateQuery(@Nullable String sourceQuery, String querySpaces);
332332

333333
@LogMessage(level = DEBUG)
334334
@Message(value = "The query [%s] updates an immutable entity: %s",
335335
id = 488)
336-
void immutableEntityUpdateQueryAllowed(String sourceQuery, String querySpaces);
336+
void immutableEntityUpdateQueryAllowed(@Nullable String sourceQuery, String querySpaces);
337337

338338
@LogMessage(level = INFO)
339339
@Message(value = "No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)", id = 489)

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/IdentifiableDomainType.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.function.Consumer;
1010
import jakarta.persistence.metamodel.IdentifiableType;
1111
import jakarta.persistence.metamodel.SingularAttribute;
12+
import org.checkerframework.checker.nullness.qual.Nullable;
1213

1314
/**
1415
* Extension to the JPA {@link IdentifiableType} contract.
@@ -18,7 +19,7 @@
1819
public interface IdentifiableDomainType<J>
1920
extends ManagedDomainType<J>, IdentifiableType<J> {
2021

21-
PathSource<?> getIdentifierDescriptor();
22+
@Nullable PathSource<?> getIdentifierDescriptor();
2223

2324
@Override
2425
<Y> SingularPersistentAttribute<? super J, Y> getId(Class<Y> type);
@@ -39,15 +40,15 @@ public interface IdentifiableDomainType<J>
3940
SimpleDomainType<?> getIdType();
4041

4142
@Override
42-
IdentifiableDomainType<? super J> getSupertype();
43+
@Nullable IdentifiableDomainType<? super J> getSupertype();
4344

4445
boolean hasIdClass();
4546

46-
SingularPersistentAttribute<? super J,?> findIdAttribute();
47+
@Nullable SingularPersistentAttribute<? super J,?> findIdAttribute();
4748

4849
void visitIdClassAttributes(Consumer<SingularPersistentAttribute<? super J,?>> action);
4950

50-
SingularPersistentAttribute<? super J, ?> findVersionAttribute();
51+
@Nullable SingularPersistentAttribute<? super J, ?> findVersionAttribute();
5152

52-
List<? extends PersistentAttribute<? super J, ?>> findNaturalIdAttributes();
53+
@Nullable List<? extends PersistentAttribute<? super J, ?>> findNaturalIdAttributes();
5354
}

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Collection;
88
import java.util.function.Consumer;
99

10+
import org.checkerframework.checker.nullness.qual.Nullable;
1011
import org.hibernate.Internal;
1112
import org.hibernate.metamodel.RepresentationMode;
1213

@@ -54,7 +55,7 @@ default Class<J> getJavaType() {
5455
/**
5556
* The descriptor of the supertype of this type.
5657
*/
57-
ManagedDomainType<? super J> getSuperType();
58+
@Nullable ManagedDomainType<? super J> getSuperType();
5859

5960
/**
6061
* The descriptors of all known managed subtypes of this type.
@@ -73,24 +74,24 @@ default Class<J> getJavaType() {
7374
@Override
7475
PersistentAttribute<J,?> getDeclaredAttribute(String name);
7576

76-
PersistentAttribute<? super J,?> findAttribute(String name);
77+
@Nullable PersistentAttribute<? super J,?> findAttribute(String name);
7778

78-
PersistentAttribute<?, ?> findSubTypesAttribute(String name);
79+
@Nullable PersistentAttribute<?, ?> findSubTypesAttribute(String name);
7980

8081
/**
8182
* @deprecated Use {@link #findAttribute(String)}
8283
*/
8384
@Deprecated(since = "7.0", forRemoval = true)
84-
default PersistentAttribute<? super J, ?> findAttributeInSuperTypes(String name) {
85+
default @Nullable PersistentAttribute<? super J, ?> findAttributeInSuperTypes(String name) {
8586
return findAttribute( name );
8687
}
8788

88-
SingularPersistentAttribute<? super J,?> findSingularAttribute(String name);
89-
PluralPersistentAttribute<? super J, ?,?> findPluralAttribute(String name);
90-
PersistentAttribute<? super J, ?> findConcreteGenericAttribute(String name);
89+
@Nullable SingularPersistentAttribute<? super J,?> findSingularAttribute(String name);
90+
@Nullable PluralPersistentAttribute<? super J, ?,?> findPluralAttribute(String name);
91+
@Nullable PersistentAttribute<? super J, ?> findConcreteGenericAttribute(String name);
9192

92-
PersistentAttribute<J,?> findDeclaredAttribute(String name);
93-
SingularPersistentAttribute<J, ?> findDeclaredSingularAttribute(String name);
94-
PluralPersistentAttribute<J, ?, ?> findDeclaredPluralAttribute(String name);
95-
PersistentAttribute<J, ?> findDeclaredConcreteGenericAttribute(String name);
93+
@Nullable PersistentAttribute<J,?> findDeclaredAttribute(String name);
94+
@Nullable SingularPersistentAttribute<J, ?> findDeclaredSingularAttribute(String name);
95+
@Nullable PluralPersistentAttribute<J, ?, ?> findDeclaredPluralAttribute(String name);
96+
@Nullable PersistentAttribute<J, ?> findDeclaredConcreteGenericAttribute(String name);
9697
}

0 commit comments

Comments
 (0)