Upgrade Gradle to 8.8, upgrade checkframework to 0.6.40, fix HibernateProcessor resources creation causing whole tests recompilation

This commit is contained in:
Andrea Boriero 2024-06-11 16:19:06 +02:00 committed by Christian Beikov
parent 0db4148205
commit 8166086957
12 changed files with 44 additions and 28 deletions

View File

@ -25,7 +25,7 @@ plugins {
id 'org.hibernate.orm.database-service' apply false id 'org.hibernate.orm.database-service' apply false
id 'biz.aQute.bnd' version '6.3.1' apply false id 'biz.aQute.bnd' version '6.3.1' apply false
id 'org.checkerframework' version '0.6.34' id 'org.checkerframework' version '0.6.40'
id 'org.hibernate.orm.build.jdks' id 'org.hibernate.orm.build.jdks'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'

View File

@ -477,6 +477,7 @@ tasks.withType(JavaCompile).configureEach { task ->
} }
checkerFramework { checkerFramework {
excludeTests = true
checkers = [ checkers = [
'org.checkerframework.checker.nullness.NullnessChecker' 'org.checkerframework.checker.nullness.NullnessChecker'
] ]

14
gradlew vendored
View File

@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045 # shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045 # shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command; # Collect all arguments for the java command:
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# shell script including quotes and variable substitutions, so put them in # and any embedded shellness will be escaped.
# double quotes to make sure that they get re-expanded; and # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# * put everything else in single quotes, so that it's not re-expanded. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \

View File

@ -57,6 +57,7 @@ import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
@ -992,7 +993,7 @@ public class ActionQueue {
protected SessionImplementor session; protected SessionImplementor session;
// Concurrency handling required when transaction completion process is dynamically registered // Concurrency handling required when transaction completion process is dynamically registered
// inside event listener (HHH-7478). // inside event listener (HHH-7478).
protected Queue<T> processes = new ConcurrentLinkedQueue<>(); protected ConcurrentLinkedQueue<@NonNull T> processes = new ConcurrentLinkedQueue<>();
private AbstractTransactionCompletionProcessQueue(SessionImplementor session) { private AbstractTransactionCompletionProcessQueue(SessionImplementor session) {
this.session = session; this.session = session;
@ -1020,9 +1021,10 @@ public class ActionQueue {
} }
public void beforeTransactionCompletion() { public void beforeTransactionCompletion() {
while ( !processes.isEmpty() ) { BeforeTransactionCompletionProcess process;
while ( ( process = processes.poll() ) != null ) {
try { try {
processes.poll().doBeforeTransactionCompletion( session ); process.doBeforeTransactionCompletion( session );
} }
catch (HibernateException he) { catch (HibernateException he) {
throw he; throw he;
@ -1050,9 +1052,10 @@ public class ActionQueue {
} }
public void afterTransactionCompletion(boolean success) { public void afterTransactionCompletion(boolean success) {
while ( !processes.isEmpty() ) { AfterTransactionCompletionProcess process;
while ( ( process = processes.poll() ) != null ) {
try { try {
processes.poll().doAfterTransactionCompletion( success, session ); process.doAfterTransactionCompletion( success, session );
} }
catch (CacheException ce) { catch (CacheException ce) {
LOG.unableToReleaseCacheLock( ce ); LOG.unableToReleaseCacheLock( ce );

View File

@ -15,8 +15,6 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.sql.DdlType; import org.hibernate.type.descriptor.sql.DdlType;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
import org.checkerframework.checker.units.qual.N;
import static org.hibernate.type.SqlTypes.ENUM; import static org.hibernate.type.SqlTypes.ENUM;
/** /**

View File

@ -14,6 +14,8 @@ import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor8; import javax.lang.model.util.SimpleTypeVisitor8;
import org.hibernate.processor.util.NullnessUtil;
import static org.hibernate.processor.util.Constants.COLLECTIONS; import static org.hibernate.processor.util.Constants.COLLECTIONS;
import static org.hibernate.processor.util.StringUtil.isProperty; import static org.hibernate.processor.util.StringUtil.isProperty;
import static org.hibernate.processor.util.TypeUtils.getCollectionElementType; import static org.hibernate.processor.util.TypeUtils.getCollectionElementType;
@ -32,14 +34,13 @@ class ContainsAttributeTypeVisitor extends SimpleTypeVisitor8<Boolean, Element>
@Override @Override
public Boolean visitDeclared(DeclaredType declaredType, Element element) { public Boolean visitDeclared(DeclaredType declaredType, Element element) {
TypeElement returnedElement = (TypeElement) context.getTypeUtils().asElement(declaredType); TypeElement returnedElement = (TypeElement) context.getTypeUtils().asElement(declaredType);
final String returnTypeName = NullnessUtil.castNonNull( returnedElement ).getQualifiedName().toString();
final String returnTypeName = returnedElement.getQualifiedName().toString();
final String collection = COLLECTIONS.get(returnTypeName); final String collection = COLLECTIONS.get(returnTypeName);
if (collection != null) { if (collection != null) {
final TypeMirror collectionElementType = final TypeMirror collectionElementType =
getCollectionElementType( declaredType, returnTypeName, null, context ); getCollectionElementType( declaredType, returnTypeName, null, context );
final Element collectionElement = context.getTypeUtils().asElement(collectionElementType); final Element collectionElement = context.getTypeUtils().asElement(collectionElementType);
if ( ElementKind.TYPE_PARAMETER == collectionElement.getKind() ) { if ( ElementKind.TYPE_PARAMETER == NullnessUtil.castNonNull( collectionElement ).getKind() ) {
return false; return false;
} }
returnedElement = (TypeElement) collectionElement; returnedElement = (TypeElement) collectionElement;

View File

@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.AnnotationValue;
@ -504,6 +505,6 @@ public final class Context {
} }
public void addEnumValue(String type, String value) { public void addEnumValue(String type, String value) {
enumTypesByValue.computeIfAbsent( value, s -> new HashSet<>() ).add( type ); enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( type );
} }
} }

View File

@ -704,7 +704,12 @@ public class HibernateProcessor extends AbstractProcessor {
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment(); final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
context.getEntityNameMappings().forEach((entityName, className) -> { context.getEntityNameMappings().forEach((entityName, className) -> {
try (Writer writer = processingEnvironment.getFiler() try (Writer writer = processingEnvironment.getFiler()
.createResource(StandardLocation.SOURCE_OUTPUT, ENTITY_INDEX, entityName) .createResource(
StandardLocation.SOURCE_OUTPUT,
ENTITY_INDEX,
entityName,
processingEnvironment.getElementUtils().getTypeElement( className )
)
.openWriter()) { .openWriter()) {
writer.append(className); writer.append(className);
} }
@ -715,8 +720,12 @@ public class HibernateProcessor extends AbstractProcessor {
} }
}); });
context.getEnumTypesByValue().forEach((valueName, enumTypeNames) -> { context.getEnumTypesByValue().forEach((valueName, enumTypeNames) -> {
try (Writer writer = processingEnvironment.getFiler() try (Writer writer = processingEnvironment.getFiler().createResource(
.createResource(StandardLocation.SOURCE_OUTPUT, ENTITY_INDEX, '.' + valueName) StandardLocation.SOURCE_OUTPUT,
ENTITY_INDEX,
'.' + valueName,
processingEnvironment.getElementUtils().getTypeElement( enumTypeNames.iterator().next() )
)
.openWriter()) { .openWriter()) {
for (String enumTypeName : enumTypeNames) { for (String enumTypeName : enumTypeNames) {
writer.append(enumTypeName).append(" "); writer.append(enumTypeName).append(" ");

View File

@ -9,6 +9,7 @@ package org.hibernate.processor.annotation;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.Context; import org.hibernate.processor.Context;
import org.hibernate.processor.util.Constants; import org.hibernate.processor.util.Constants;
import org.hibernate.processor.util.NullnessUtil;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
@ -72,7 +73,7 @@ public class DataMetaAttributeGenerationVisitor extends SimpleTypeVisitor8<@Null
public @Nullable DataAnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) { public @Nullable DataAnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType ); final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
// WARNING: .toString() is necessary here since Name equals does not compare to String // WARNING: .toString() is necessary here since Name equals does not compare to String
final String returnTypeName = returnedElement.getQualifiedName().toString(); final String returnTypeName = NullnessUtil.castNonNull( returnedElement ).getQualifiedName().toString();
final String collection = Constants.COLLECTIONS.get( returnTypeName ); final String collection = Constants.COLLECTIONS.get( returnTypeName );
final String targetEntity = getTargetEntity( element.getAnnotationMirrors() ); final String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) { if ( collection != null ) {

View File

@ -11,6 +11,7 @@ import org.hibernate.processor.Context;
import org.hibernate.processor.util.AccessType; import org.hibernate.processor.util.AccessType;
import org.hibernate.processor.util.AccessTypeInformation; import org.hibernate.processor.util.AccessTypeInformation;
import org.hibernate.processor.util.Constants; import org.hibernate.processor.util.Constants;
import org.hibernate.processor.util.NullnessUtil;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
@ -84,8 +85,9 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor8<@Nullable
@Override @Override
public @Nullable AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) { public @Nullable AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType ); final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
assert returnedElement != null;
// WARNING: .toString() is necessary here since Name equals does not compare to String // WARNING: .toString() is necessary here since Name equals does not compare to String
final String returnTypeName = returnedElement.getQualifiedName().toString(); final String returnTypeName = NullnessUtil.castNonNull( returnedElement ).getQualifiedName().toString();
final String collection = Constants.COLLECTIONS.get( returnTypeName ); final String collection = Constants.COLLECTIONS.get( returnTypeName );
final String targetEntity = getTargetEntity( element.getAnnotationMirrors() ); final String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) { if ( collection != null ) {
@ -109,7 +111,7 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor8<@Nullable
getCollectionElementType( declaredType, returnTypeName, explicitTargetEntity, context ); getCollectionElementType( declaredType, returnTypeName, explicitTargetEntity, context );
if ( collectionElementType.getKind() == TypeKind.DECLARED ) { if ( collectionElementType.getKind() == TypeKind.DECLARED ) {
final TypeElement collectionElement = (TypeElement) typeUtils().asElement( collectionElementType ); final TypeElement collectionElement = (TypeElement) typeUtils().asElement( collectionElementType );
setAccessType( collectionElementType, collectionElement ); setAccessType( collectionElementType, NullnessUtil.castNonNull( collectionElement ) );
} }
} }
return createMetaAttribute( declaredType, element, collection, targetEntity ); return createMetaAttribute( declaredType, element, collection, targetEntity );

View File

@ -6,8 +6,8 @@
*/ */
package org.hibernate.processor.util; package org.hibernate.processor.util;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.processor.Context; import org.hibernate.processor.Context;
import org.hibernate.processor.util.Constants;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind; import javax.lang.model.element.ElementKind;
@ -46,7 +46,7 @@ class BasicAttributeVisitor extends SimpleTypeVisitor8<Boolean, Element> {
public Boolean visitArray(ArrayType arrayType, Element element) { public Boolean visitArray(ArrayType arrayType, Element element) {
final TypeElement componentElement = (TypeElement) final TypeElement componentElement = (TypeElement)
context.getTypeUtils().asElement( arrayType.getComponentType() ); context.getTypeUtils().asElement( arrayType.getComponentType() );
return BASIC_ARRAY_TYPES.contains( componentElement.getQualifiedName().toString() ); return BASIC_ARRAY_TYPES.contains( NullnessUtil.castNonNull( componentElement ).getQualifiedName().toString() );
} }
@Override @Override

View File

@ -665,7 +665,7 @@ public final class TypeUtils {
public @Nullable TypeElement visitDeclared(DeclaredType declaredType, Element element) { public @Nullable TypeElement visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) final TypeElement returnedElement = (TypeElement)
context.getTypeUtils().asElement( declaredType ); context.getTypeUtils().asElement( declaredType );
return containsAnnotation( returnedElement, EMBEDDABLE ) ? returnedElement : null; return containsAnnotation( NullnessUtil.castNonNull( returnedElement ), EMBEDDABLE ) ? returnedElement : null;
} }
@Override @Override