Skip to content

Commit

Permalink
Upgrade Gradle to 8.8, upgrade checkframework to 0.6.40, fix Hibernat…
Browse files Browse the repository at this point in the history
…eProcessor resources creation causing whole tests recompilation
  • Loading branch information
dreab8 authored and beikov committed Jun 11, 2024
1 parent 0db4148 commit 8166086
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
id 'org.hibernate.orm.database-service' 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 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
Expand Down
1 change: 1 addition & 0 deletions gradle/java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ tasks.withType(JavaCompile).configureEach { task ->
}

checkerFramework {
excludeTests = true
checkers = [
'org.checkerframework.checker.nullness.NullnessChecker'
]
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# 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 ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# 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" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -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.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
Expand Down Expand Up @@ -992,7 +993,7 @@ private abstract static class AbstractTransactionCompletionProcessQueue<T> {
protected SessionImplementor session;
// Concurrency handling required when transaction completion process is dynamically registered
// inside event listener (HHH-7478).
protected Queue<T> processes = new ConcurrentLinkedQueue<>();
protected ConcurrentLinkedQueue<@NonNull T> processes = new ConcurrentLinkedQueue<>();

private AbstractTransactionCompletionProcessQueue(SessionImplementor session) {
this.session = session;
Expand Down Expand Up @@ -1020,9 +1021,10 @@ private BeforeTransactionCompletionProcessQueue(SessionImplementor session) {
}

public void beforeTransactionCompletion() {
while ( !processes.isEmpty() ) {
BeforeTransactionCompletionProcess process;
while ( ( process = processes.poll() ) != null ) {
try {
processes.poll().doBeforeTransactionCompletion( session );
process.doBeforeTransactionCompletion( session );
}
catch (HibernateException he) {
throw he;
Expand Down Expand Up @@ -1050,9 +1052,10 @@ public void addSpaceToInvalidate(String space) {
}

public void afterTransactionCompletion(boolean success) {
while ( !processes.isEmpty() ) {
AfterTransactionCompletionProcess process;
while ( ( process = processes.poll() ) != null ) {
try {
processes.poll().doAfterTransactionCompletion( success, session );
process.doAfterTransactionCompletion( success, session );
}
catch (CacheException ce) {
LOG.unableToReleaseCacheLock( ce );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import org.hibernate.type.descriptor.sql.DdlType;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;

import org.checkerframework.checker.units.qual.N;

import static org.hibernate.type.SqlTypes.ENUM;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javax.lang.model.type.TypeMirror;
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.StringUtil.isProperty;
import static org.hibernate.processor.util.TypeUtils.getCollectionElementType;
Expand All @@ -32,14 +34,13 @@ class ContainsAttributeTypeVisitor extends SimpleTypeVisitor8<Boolean, Element>
@Override
public Boolean visitDeclared(DeclaredType declaredType, Element element) {
TypeElement returnedElement = (TypeElement) context.getTypeUtils().asElement(declaredType);

final String returnTypeName = returnedElement.getQualifiedName().toString();
final String returnTypeName = NullnessUtil.castNonNull( returnedElement ).getQualifiedName().toString();
final String collection = COLLECTIONS.get(returnTypeName);
if (collection != null) {
final TypeMirror collectionElementType =
getCollectionElementType( declaredType, returnTypeName, null, context );
final Element collectionElement = context.getTypeUtils().asElement(collectionElementType);
if ( ElementKind.TYPE_PARAMETER == collectionElement.getKind() ) {
if ( ElementKind.TYPE_PARAMETER == NullnessUtil.castNonNull( collectionElement ).getKind() ) {
return false;
}
returnedElement = (TypeElement) collectionElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
Expand Down Expand Up @@ -504,6 +505,6 @@ public Map<String,Set<String>> getEnumTypesByValue() {
}

public void addEnumValue(String type, String value) {
enumTypesByValue.computeIfAbsent( value, s -> new HashSet<>() ).add( type );
enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( type );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,12 @@ private void writeIndex() {
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
context.getEntityNameMappings().forEach((entityName, className) -> {
try (Writer writer = processingEnvironment.getFiler()
.createResource(StandardLocation.SOURCE_OUTPUT, ENTITY_INDEX, entityName)
.createResource(
StandardLocation.SOURCE_OUTPUT,
ENTITY_INDEX,
entityName,
processingEnvironment.getElementUtils().getTypeElement( className )
)
.openWriter()) {
writer.append(className);
}
Expand All @@ -715,8 +720,12 @@ private void writeIndex() {
}
});
context.getEnumTypesByValue().forEach((valueName, enumTypeNames) -> {
try (Writer writer = processingEnvironment.getFiler()
.createResource(StandardLocation.SOURCE_OUTPUT, ENTITY_INDEX, '.' + valueName)
try (Writer writer = processingEnvironment.getFiler().createResource(
StandardLocation.SOURCE_OUTPUT,
ENTITY_INDEX,
'.' + valueName,
processingEnvironment.getElementUtils().getTypeElement( enumTypeNames.iterator().next() )
)
.openWriter()) {
for (String enumTypeName : enumTypeNames) {
writer.append(enumTypeName).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.Context;
import org.hibernate.processor.util.Constants;
import org.hibernate.processor.util.NullnessUtil;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
Expand Down Expand Up @@ -72,7 +73,7 @@ private Types typeUtils() {
public @Nullable DataAnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
// 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 targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.processor.util.AccessType;
import org.hibernate.processor.util.AccessTypeInformation;
import org.hibernate.processor.util.Constants;
import org.hibernate.processor.util.NullnessUtil;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
Expand Down Expand Up @@ -84,8 +85,9 @@ private Types typeUtils() {
@Override
public @Nullable AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
assert returnedElement != null;
// 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 targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) {
Expand All @@ -109,7 +111,7 @@ private AnnotationMetaAttribute createMetaCollectionAttribute(
getCollectionElementType( declaredType, returnTypeName, explicitTargetEntity, context );
if ( collectionElementType.getKind() == TypeKind.DECLARED ) {
final TypeElement collectionElement = (TypeElement) typeUtils().asElement( collectionElementType );
setAccessType( collectionElementType, collectionElement );
setAccessType( collectionElementType, NullnessUtil.castNonNull( collectionElement ) );
}
}
return createMetaAttribute( declaredType, element, collection, targetEntity );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
package org.hibernate.processor.util;

import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.processor.Context;
import org.hibernate.processor.util.Constants;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -46,7 +46,7 @@ public Boolean visitPrimitive(PrimitiveType primitiveType, Element element) {
public Boolean visitArray(ArrayType arrayType, Element element) {
final TypeElement componentElement = (TypeElement)
context.getTypeUtils().asElement( arrayType.getComponentType() );
return BASIC_ARRAY_TYPES.contains( componentElement.getQualifiedName().toString() );
return BASIC_ARRAY_TYPES.contains( NullnessUtil.castNonNull( componentElement ).getQualifiedName().toString() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ static class EmbeddedAttributeVisitor extends SimpleTypeVisitor8<@Nullable TypeE
public @Nullable TypeElement visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement)
context.getTypeUtils().asElement( declaredType );
return containsAnnotation( returnedElement, EMBEDDABLE ) ? returnedElement : null;
return containsAnnotation( NullnessUtil.castNonNull( returnedElement ), EMBEDDABLE ) ? returnedElement : null;
}

@Override
Expand Down

0 comments on commit 8166086

Please sign in to comment.