Skip to content

Commit

Permalink
build: add ErrorProne + NullAway
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Nov 22, 2024
1 parent 456fad3 commit 7f6a229
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 11 deletions.
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ repositories {
dependencies {
implementation("com.adarshr:gradle-test-logger-plugin:4.0.0")
implementation("io.github.joselion:strict-null-check:3.5.0")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.1.0")
implementation("net.ltgt.gradle:gradle-nullaway-plugin:2.1.0")
}
97 changes: 96 additions & 1 deletion buildSrc/src/main/kotlin/framefork.java.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import net.ltgt.gradle.errorprone.errorprone
import net.ltgt.gradle.nullaway.nullaway

plugins {
`java-library`
id("idea")
id("com.adarshr.test-logger")
id("io.github.joselion.strict-null-check")
id("net.ltgt.errorprone")
id("net.ltgt.nullaway")
}

repositories {
Expand All @@ -23,6 +27,17 @@ java {
dependencies {
api("org.jspecify:jspecify:1.0.0")

compileOnly("org.checkerframework:checker-qual:3.48.2")

errorprone("com.google.errorprone:error_prone_core:2.36.0")
errorprone("com.uber.nullaway:nullaway:0.12.1")

constraints {
errorprone("org.checkerframework:checker-qual:3.48.2")
errorprone("org.checkerframework:dataflow-errorprone:3.48.2")
errorprone("org.checkerframework:dataflow-nullaway:3.48.2")
errorprone("com.google.guava:guava:33.3.1-jre")
}
}

strictNullCheck {
Expand Down Expand Up @@ -53,9 +68,89 @@ tasks.withType<Test> {
}
}

nullaway {
annotatedPackages.add("org.framefork")
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-parameters"))
options.compilerArgs.add("-Xlint:all,-fallthrough,-processing,-serial,-classfile,-path,-this-escape")
options.compilerArgs.add("-parameters")
options.compilerArgs.add("-Werror") // treat warnings as errors

// useful when debugging lint errors:
// options.isVerbose = true
// options.isDebug = true

options.errorprone {
disableWarningsInGeneratedCode.set(true)
allDisabledChecksAsWarnings.set(true)
allErrorsAsWarnings.set(true)
disable("AndroidJdkLibsChecker")
disable("AnnotationPosition")
disable("AvoidObjectArrays")
disable("BooleanParameter")
disable("CanIgnoreReturnValueSuggester")
disable("CatchingUnchecked")
disable("ConstantPatternCompile")
disable("DefaultLocale")
disable("DeduplicateConstants")
disable("DistinctVarargsChecker")
disable("FieldCanBeFinal")
disable("ImmutableMemberCollection")
disable("InconsistentOverloads")
disable("InlineMeSuggester")
disable("InterfaceWithOnlyStatics")
disable("Interruption")
disable("InvalidBlockTag")
disable("Java7ApiChecker")
disable("Java8ApiChecker")
disable("MemberName")
disable("MethodCanBeStatic")
disable("MissingSummary")
disable("MockitoDoSetup")
disable("OptionalOfRedundantMethod")
disable("PreferredInterfaceType")
disable("ReturnMissingNullable")
disable("SameNameButDifferent")
disable("StatementSwitchToExpressionSwitch")
disable("StaticOrDefaultInterfaceMethod")
disable("StaticQualifiedUsingExpression")
disable("StringSplitter")
disable("SuppressWarningsWithoutExplanation")
disable("TooManyParameters")
disable("TraditionalSwitchExpression")
disable("TryFailRefactoring")
disable("TypeParameterNaming")
disable("UnnecessaryFinal")
disable("UnnecessaryStringBuilder")
disable("Var")
disable("WildcardImport")
disable("YodaCondition")
}

options.errorprone.nullaway {
warn()
treatGeneratedAsUnannotated.set(true)
acknowledgeRestrictiveAnnotations.set(true)
handleTestAssertionLibraries.set(true)
checkContracts.set(true)
knownInitializers.addAll(setOf(
"org.springframework.beans.factory.InitializingBean.afterPropertiesSet",
))
customInitializerAnnotations.addAll(setOf(
"org.junit.jupiter.api.BeforeAll",
"org.junit.jupiter.api.BeforeEach",
))
excludedFieldAnnotations.addAll(setOf(
"jakarta.persistence.PersistenceContext",
"org.springframework.beans.factory.annotation.Autowired",
"org.springframework.boot.test.mock.mockito.MockBean",
"org.mockito.Captor",
"org.springframework.beans.factory.annotation.Value",
"com.github.rvesse.airline.annotations.Option"
))
}
}

tasks.withType<Javadoc> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Comparator;
import java.util.List;

@SuppressWarnings("rawtypes")
@AutoService(TypeContributor.class)
public class ObjectUuidTypesContributor implements TypeContributor
{
Expand All @@ -36,11 +37,12 @@ public class ObjectUuidTypesContributor implements TypeContributor
private static final boolean CLASS_INDEX_PRESENT;

static {
boolean found = false;
boolean found;
try {
Class.forName("org.atteo.classindex.ClassIndex");
found = true;
} catch (ClassNotFoundException ignored) {
found = false;
}

CLASS_INDEX_PRESENT = found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ArticleDefaultExplicitMapping(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleDefaultExplicitMapping()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Comparator;
import java.util.List;

@SuppressWarnings("rawtypes")
@AutoService(TypeContributor.class)
public class ObjectUuidTypesContributor implements TypeContributor
{
Expand All @@ -36,11 +37,12 @@ public class ObjectUuidTypesContributor implements TypeContributor
private static final boolean CLASS_INDEX_PRESENT;

static {
boolean found = false;
boolean found;
try {
Class.forName("org.atteo.classindex.ClassIndex");
found = true;
} catch (ClassNotFoundException ignored) {
found = false;
}

CLASS_INDEX_PRESENT = found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ArticleDefaultExplicitMapping(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleDefaultExplicitMapping()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.testcontainers.containers.JdbcDatabaseContainer;

import javax.sql.DataSource;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

public abstract class AbstractContainerDataSourceProvider implements DataSourceProvider
Expand All @@ -21,7 +22,7 @@ public JdbcDatabaseContainer<?> getContainer()
}
}

return container.get();
return Objects.requireNonNull(container.get(), "database container must not be null");
}

private JdbcDatabaseContainer<?> initContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public String hibernateDialect()
return MySQLDialect.class.getName();
}

@Override
protected DataSource newDataSource()
{
var dataSource = new MysqlDataSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public String hibernateDialect()
return PostgreSQLDialect.class.getName();
}

@Override
protected DataSource newDataSource()
{
var dataSource = new PGSimpleDataSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public String toString()
@Override
public boolean equals(@Nullable final Object o)
{
if (!(o instanceof ObjectUuid)) {
if (!(o instanceof ObjectUuid<?>)) {
return false;
}
if (!this.getClass().isInstance(o)) {
Expand Down Expand Up @@ -233,7 +233,7 @@ static UuidGenerator getGenerator(final Function<?, ?> constructor)
{
return GENERATORS.computeIfAbsent(
constructor,
c -> FACTORY.get().getGenerator(c)
c -> Objects.requireNonNull(FACTORY.get(), "generator factory must not be null").getGenerator(c)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.module.SimpleDeserializers;
import com.fasterxml.jackson.databind.module.SimpleSerializers;
import com.google.auto.service.AutoService;
import org.framefork.typedIds.uuid.ObjectUuid;
import org.framefork.typedIds.uuid.ObjectUuidTypeUtils;

@AutoService(Module.class)
public class ObjectUuidJacksonModule extends Module
Expand Down Expand Up @@ -34,7 +34,7 @@ private static SimpleSerializers getSerializers()
{
var serializers = new SimpleSerializers();

serializers.addSerializer(ObjectUuid.class, new ObjectUuidSerializer());
serializers.addSerializer(ObjectUuidTypeUtils.getObjectUuidRawClass(), new ObjectUuidSerializer());

return serializers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import java.io.IOException;

@SuppressWarnings("rawtypes")
public class ObjectUuidSerializer extends JsonSerializer<ObjectUuid>
public class ObjectUuidSerializer extends JsonSerializer<ObjectUuid<?>>
{

@Override
public void serialize(
final ObjectUuid uuid,
final ObjectUuid<?> uuid,
final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider
) throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ArticleTestingEntity(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleTestingEntity()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ArticleTestingEntity(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleTestingEntity()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ArticleTestingEntity(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleTestingEntity()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ArticleTestingEntity(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleTestingEntity()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ArticleTestingEntity(final String title)
this.title = title;
}

@SuppressWarnings("NullAway")
protected ArticleTestingEntity()
{
}
Expand Down

0 comments on commit 7f6a229

Please sign in to comment.