Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ plugins {
id 'biz.aQute.bnd' version '7.1.0' apply false

id "com.diffplug.spotless" version "7.0.4"
id 'org.checkerframework' version '0.6.56'
//id 'org.checkerframework' version '0.6.56'
id "net.ltgt.errorprone" version "4.3.0"
id "net.ltgt.nullaway" version "2.3.0"
id 'org.hibernate.orm.build.jdks'

id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ description = 'Hibernate\'s community supported dialects'
dependencies {
api project( ':hibernate-core' )

compileOnly libs.checkerFramework

testImplementation project( ':hibernate-testing' )
testImplementation project( path: ':hibernate-core', configuration: 'tests' )
}
Expand Down
5 changes: 4 additions & 1 deletion hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ configurations {
}
}


dependencies {
api jakartaLibs.jpa
api jakartaLibs.jta
Expand All @@ -35,6 +34,8 @@ dependencies {

implementation libs.antlrRuntime

compileOnly libs.checkerFramework

compileOnly jakartaLibs.jacc
compileOnly jakartaLibs.validation
compileOnly jakartaLibs.cdi
Expand All @@ -61,6 +62,8 @@ dependencies {
testImplementation jdbcLibs.h2
testImplementation libs.hibernateModelsJandex

testCompileOnly libs.checkerFramework

testRuntimeOnly libs.byteBuddy
testRuntimeOnly testLibs.weld
testRuntimeOnly testLibs.wildFlyTxnClient
Expand Down
2 changes: 2 additions & 0 deletions hibernate-micrometer/hibernate-micrometer.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies {
implementation project( ':hibernate-core' )
implementation libs.micrometer

compileOnly libs.checkerFramework

testImplementation project( ':hibernate-testing' )

testAnnotationProcessor project( ':hibernate-processor' )
Expand Down
2 changes: 2 additions & 0 deletions hibernate-vector/hibernate-vector.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ description = 'Hibernate\'s extensions for vector support'
dependencies {
api project( ':hibernate-core' )

compileOnly libs.checkerFramework

testImplementation project( ':hibernate-testing' )
testImplementation project( path: ':hibernate-core', configuration: 'tests' )
}
Expand Down
44 changes: 40 additions & 4 deletions local-build-plugins/src/main/groovy/local.code-quality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*/

plugins {
id "org.checkerframework"
//id "org.checkerframework"
id "net.ltgt.errorprone"
id "net.ltgt.nullaway"
id "de.thetaphi.forbiddenapis"
id "com.diffplug.spotless"
}
Expand Down Expand Up @@ -106,11 +108,44 @@ spotless {
tasks.compileJava.dependsOn tasks.spotlessJavaApply

dependencies {
compileOnly libs.checkerFramework
testCompileOnly libs.checkerFramework
checkerFramework libs.checkerFrameworkChecker
//compileOnly libs.checkerFramework
//testCompileOnly libs.checkerFramework
//checkerFramework libs.checkerFrameworkChecker
api "org.jspecify:jspecify:1.0.0"
// for use contract like @Nullable Boolean foo(final String a) @Contract(null->null)
// see https://github.com/uber/NullAway/wiki/Supported-Annotations#contracts
// compileOnly "org.jetbrains:annotations:26.0.2"
errorprone "com.uber.nullaway:nullaway:0.12.9"
errorprone "com.google.errorprone:error_prone_core:2.41.0"
}

tasks.withType(JavaCompile).configureEach {
if (gradle.startParameter.taskNames.contains("ciCheck")) {
// options.errorprone.enabled = true
}
if (it.name.toLowerCase().contains("test")) {
options.errorprone.enabled = false
}
options.errorprone {
disableWarningsInGeneratedCode.set(true)

// error prone core = warnings
errorproneArgs.add("-XepAllErrorsAsWarnings")

nullaway {
error()
// annotatedPackages.add("org.hibernate")
onlyNullMarked.set(true)
treatGeneratedAsUnannotated.set(true)
checkContracts.set(true)
checkOptionalEmptiness.set(true)
exhaustiveOverride.set(true)
jspecifyMode.set(true)
}
}
}

/*
checkerFramework {
excludeTests = true
skipCheckerFramework = !gradle.startParameter.taskNames.contains("ciCheck")
Expand All @@ -123,6 +158,7 @@ checkerFramework {
'-AonlyDefs=^org\\.hibernate\\.(jdbc|exception|integrator|processor|service|spi|pretty|property\\.access|stat|engine\\.(config|jndi|profile|spi|transaction)|(action|context|bytecode)\\.spi)\\.'
]
}
*/

tasks.forbiddenApisMain {
// unfortunately we currently have many uses of default Locale implicitly (~370)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.hibernate.jpamodelgen;

import org.hibernate.processor.HibernateProcessor;
import org.jspecify.annotations.NonNull;

import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
Expand Down Expand Up @@ -65,7 +66,7 @@
@Deprecated(forRemoval = true)
public class JPAMetaModelEntityProcessor extends HibernateProcessor {
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
public synchronized void init(@NonNull ProcessingEnvironment processingEnvironment) {
processingEnvironment.getMessager().printMessage(
Diagnostic.Kind.WARNING,
"JPAMetaModelEntityProcessor is deprecated, replaced by org.hibernate.processor.HibernateProcessor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Set;

import static java.util.Objects.requireNonNull;
import static org.hibernate.processor.util.Constants.SPRING_COMPONENT;
import static org.hibernate.processor.util.TypeUtils.getGeneratedClassFullyQualifiedName;
import static org.hibernate.processor.util.TypeUtils.isMemberType;
Expand Down Expand Up @@ -270,7 +271,7 @@ private static String getGeneratedSuperclassName(Element superClassElement, bool

private static String getGeneratedClassName(TypeElement typeElement, boolean jakartaDataStyle) {
final String simpleName = typeElement.getSimpleName().toString();
final Element enclosingElement = typeElement.getEnclosingElement();
final Element enclosingElement = requireNonNull( typeElement.getEnclosingElement() );
return (enclosingElement instanceof TypeElement
? getGeneratedSuperclassName( enclosingElement, jakartaDataStyle )
: ((PackageElement) enclosingElement).getQualifiedName().toString())
Expand Down Expand Up @@ -305,6 +306,9 @@ private static String writeGeneratedAnnotation(Metamodel entity, Context context
private static String writeSuppressWarnings(Context context) {
final StringBuilder annotation = new StringBuilder("@SuppressWarnings({");
final String[] warnings = context.getSuppressedWarnings();
if (warnings == null || warnings.length == 0) {
return "@SuppressWarnings({})";
}
for (int i = 0; i < warnings.length; i++) {
if ( i>0 ) {
annotation.append(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.hibernate.processor.util.AccessTypeInformation;

import jakarta.persistence.AccessType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;

import static java.lang.Boolean.parseBoolean;
import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -81,16 +81,16 @@ public final class Context {
* Whether all mapping files are xml-mapping-metadata-complete. In this case no annotation processing will take
* place.
*/
private Boolean fullyXmlConfigured;
private @Nullable Boolean fullyXmlConfigured;
private boolean addInjectAnnotation = false;
private boolean addDependentAnnotation = false;
private boolean addComponentAnnotation = false;
private boolean addNonnullAnnotation = false;
private boolean addGeneratedAnnotation = true;
private boolean addGenerationDate;
private String[] suppressedWarnings;
private String @Nullable [] suppressedWarnings;
private boolean addTransactionScopedAnnotation;
private AccessType persistenceUnitDefaultAccessType;
private @Nullable AccessType persistenceUnitDefaultAccessType;
private boolean generateJakartaDataStaticMetamodel;
private boolean quarkusInjection;
private boolean springInjection;
Expand Down Expand Up @@ -213,7 +213,7 @@ public boolean addSuppressWarningsAnnotation() {
return suppressedWarnings != null;
}

public String[] getSuppressedWarnings() {
public String @Nullable [] getSuppressedWarnings() {
return suppressedWarnings;
}

Expand Down Expand Up @@ -402,7 +402,7 @@ public void mappingDocumentFullyXmlConfigured(boolean fullyXmlConfigured) {
: this.fullyXmlConfigured && fullyXmlConfigured;
}

public AccessType getPersistenceUnitDefaultAccessType() {
public @Nullable AccessType getPersistenceUnitDefaultAccessType() {
return persistenceUnitDefaultAccessType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.processor;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;
import org.hibernate.processor.annotation.AnnotationMetaEntity;
import org.hibernate.processor.annotation.AnnotationMetaPackage;
import org.hibernate.processor.annotation.NonManagedMetamodel;
Expand Down Expand Up @@ -45,6 +45,7 @@
import java.util.function.Function;

import static java.lang.Boolean.parseBoolean;
import static java.util.Objects.requireNonNull;
import static javax.lang.model.util.ElementFilter.fieldsIn;
import static javax.lang.model.util.ElementFilter.methodsIn;
import static org.hibernate.processor.HibernateProcessor.ADD_GENERATED_ANNOTATION;
Expand Down Expand Up @@ -512,7 +513,7 @@ private void createMetaModelClasses() {

for ( Metamodel aux : context.getMetaAuxiliaries() ) {
if ( !context.isAlreadyGenerated(aux)
&& !isClassRecordOrInterfaceType( aux.getElement().getEnclosingElement() ) ) {
&& !isClassRecordOrInterfaceType( requireNonNull( aux.getElement().getEnclosingElement() ) ) ) {
context.logMessage( Diagnostic.Kind.OTHER,
"Writing metamodel for auxiliary '" + aux + "'" );
ClassWriter.writeFile( aux, context );
Expand Down Expand Up @@ -711,7 +712,7 @@ && hasAnnotation( element, ENTITY, MAPPED_SUPERCLASS )
}

private static boolean hasHandwrittenMetamodel(Element element) {
return element.getEnclosingElement().getEnclosedElements()
return requireNonNull( element.getEnclosingElement() ).getEnclosedElements()
.stream().anyMatch(e -> e.getSimpleName()
.contentEquals('_' + element.getSimpleName().toString()));
}
Expand Down Expand Up @@ -764,7 +765,7 @@ private void indexEnumValues(TypeMirror type) {
if ( fieldType.getKind() == ElementKind.ENUM ) {
for ( Element enumMember : fieldType.getEnclosedElements() ) {
if ( enumMember.getKind() == ElementKind.ENUM_CONSTANT ) {
final Element enclosingElement = fieldType.getEnclosingElement();
final Element enclosingElement = requireNonNull( fieldType.getEnclosingElement() );
final boolean hasOuterType =
enclosingElement.getKind().isClass() || enclosingElement.getKind().isInterface();
context.addEnumValue( fieldType.getQualifiedName().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.hibernate.processor.util.NullnessUtil;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;

/**
* Information about the Meta Model Generator version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.processor.annotation;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.processor.annotation;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;

import javax.lang.model.element.ExecutableElement;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.processor.annotation;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;
import org.hibernate.AssertionFailure;

import javax.lang.model.element.ExecutableElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jspecify.annotations.Nullable;
import org.hibernate.processor.Context;
import org.hibernate.processor.model.MetaAttribute;
import org.hibernate.processor.model.Metamodel;
Expand All @@ -22,6 +22,7 @@
import java.util.List;

import static java.lang.Character.isJavaIdentifierStart;
import static java.util.Objects.requireNonNull;
import static org.hibernate.processor.util.Constants.ENTITY_GRAPH;
import static org.hibernate.processor.util.Constants.HIB_ENABLED_FETCH_PROFILE;
import static org.hibernate.processor.util.Constants.JAVA_OBJECT;
Expand Down Expand Up @@ -56,7 +57,7 @@ void addAuxiliaryMembers() {

void checkNamedQueries() {
boolean checkHql = containsAnnotation( getElement(), Constants.CHECK_HQL )
|| containsAnnotation( getElement().getEnclosingElement(), Constants.CHECK_HQL );
|| containsAnnotation( requireNonNull( getElement().getEnclosingElement() ), Constants.CHECK_HQL );
handleNamedQueryAnnotation( NAMED_QUERY, checkHql );
handleNamedQueryRepeatableAnnotation( Constants.NAMED_QUERIES, checkHql );
handleNamedQueryAnnotation( Constants.HIB_NAMED_QUERY, checkHql );
Expand Down
Loading