Skip to content
Open
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
5 changes: 5 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repositories {

dependencies {
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.2.5")
implementation("org.checkerframework:checkerframework-gradle-plugin:0.6.61")
}

gradlePlugin {
Expand All @@ -26,5 +27,9 @@ gradlePlugin {
id = "com.navercorp.fixturemonkey.gradle.plugin.object-farm-maven-publish-conventions"
implementationClass = "com.navercorp.fixturemonkey.gradle.plugin.ObjectFarmMavenPublishConventionsPlugin"
}
register("checkerFrameworkConventionsPlugin") {
id = "com.navercorp.fixturemonkey.gradle.plugin.checker-framework-conventions"
implementationClass = "com.navercorp.fixturemonkey.gradle.plugin.CheckerFrameworkConventionsPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Fixture Monkey
*
* Copyright (c) 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.fixturemonkey.gradle.plugin

import org.checkerframework.gradle.plugin.CheckerFrameworkExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

class CheckerFrameworkConventionsPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.plugins.apply("org.checkerframework")

project.extensions.getByType<CheckerFrameworkExtension>().apply {
checkers = listOf("org.checkerframework.checker.nullness.NullnessChecker")
extraJavacArgs = listOf(
"-AsuppressWarnings=initialization,method.invocation,type.arguments"
)
excludeTests = true
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.gradle.api.Project

class JavaConventionsPlugin : Plugin<Project> {
override fun apply(project: Project) {
CheckerFrameworkConventionsPlugin().apply(project)
CheckstyleConventionsPlugin().apply(project)
SpotbugsConventionsPlugin().apply(project)
JacocoConventionsPlugin().apply(project)
Expand Down
3 changes: 3 additions & 0 deletions fixture-monkey-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ multiReleaseVersions.forEach { releaseVersion ->
.replaceFirstChar { it.lowercase() }

configuration.extendsFrom(configurations.getByName(defaultVersionConfigurationName))

val checkerFrameworkExtension = project.extensions.findByType<org.checkerframework.gradle.plugin.CheckerFrameworkExtension>()
checkerFrameworkExtension?.skipCheckerFramework = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class ContainerCombinableArbitrary<T> implements CombinableArbitrary<T> {
}

@Override
@SuppressWarnings("type.arguments.not.inferred")
public T combined() {
List<Object> combinedList = combinableArbitraryList.stream()
.map(CombinableArbitrary::combined)
Expand All @@ -57,6 +58,7 @@ public T combined() {
}

@Override
@SuppressWarnings({"return"})
public Object rawValue() {
List<Object> rawValues = combinableArbitraryList.stream()
.map(CombinableArbitrary::rawValue)
Expand Down Expand Up @@ -85,6 +87,7 @@ public boolean fixed() {
}

@Override
@SuppressWarnings("argument")
public CombinableArbitrary<T> unique() {
List<CombinableArbitrary<?>> uniqueCombinableArbitraryList = this.combinableArbitraryList.stream()
.map(arbitrary -> arbitrary.filter(it -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public T combined() {
throw newRetryableFilterMissException(lastException);
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "override.return", "argument"})
@Override
public T rawValue() {
T returned;
Expand Down Expand Up @@ -205,6 +205,7 @@ public CombinableArbitrary<T> unique() {
return combinableArbitrary.unique();
}

@SuppressWarnings("argument")
private RetryableFilterMissException newRetryableFilterMissException(@Nullable Throwable throwable) {
if (!(throwable instanceof RetryableFilterMissException)) {
return new RetryableFilterMissException(throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.jspecify.annotations.Nullable;

/**
* It would generate a fixed value {@code object}.
Expand All @@ -40,6 +41,7 @@ public T combined() {
}

@Override
@SuppressWarnings("override.return")
public T rawValue() {
return object;
}
Expand All @@ -54,7 +56,7 @@ public boolean fixed() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public T combined() {
}

@Override
@SuppressWarnings("return")
public Object rawValue() {
Object rawValue = introspected.getValue();
introspected.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public U combined() {
return mapper.apply(combinableArbitrary.combined());
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "return"})
@Override
public U rawValue() {
public Object rawValue() {
try {
return mapper.apply((T)combinableArbitrary.rawValue());
} catch (ClassCastException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import net.jqwik.api.Arbitrary;
import net.jqwik.api.EdgeCases;
Expand All @@ -57,16 +59,17 @@ public final class MonkeyStringArbitrary implements StringArbitrary {
private CharacterArbitrary characterArbitrary = new DefaultCharacterArbitrary();

private int minLength = 0;
private Integer maxLength = null;
private @Nullable Integer maxLength = null;
private Predicate<Character> filter = c -> true;
@SuppressWarnings("assignment")
private RandomDistribution lengthDistribution = null;
private double repeatChars = 0.0;

@Override
public RandomGenerator<String> generator(int genSize) {
long maxUniqueChars = characterArbitrary
.exhaustive(maxLength())
.map(ExhaustiveGenerator::maxCount)
.<@NonNull Long>map(ExhaustiveGenerator::maxCount)
.orElse((long)maxLength());
return RandomGenerators.strings(
randomCharacterGenerator(),
Expand All @@ -82,6 +85,7 @@ public RandomGenerator<String> generator(int genSize, boolean withEdgeCases) {
return this.generator(genSize);
}

@SuppressWarnings("argument")
private int maxLength() {
return RandomGenerators.collectionMaxSize(minLength, maxLength);
}
Expand Down Expand Up @@ -250,7 +254,7 @@ public StringArbitrary excludeChars(char... charsToExclude) {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class NullInjectCombinableArbitrary<T> implements CombinableArbitrary<T> {
this.nullProbability = nullProbability;
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "argument"})
@Override
public T combined() {
T combined = combinableArbitrary.combined();
Expand All @@ -50,6 +50,7 @@ public T combined() {
return (T)injectNull(combined);
}

@SuppressWarnings("return")
@Override
public Object rawValue() {
Object rawValue = combinableArbitrary.rawValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final class ObjectCombinableArbitrary<T> implements CombinableArbitrary<T> {
this.combinator = combinator;
}

@SuppressWarnings("argument")
@Override
public T combined() {
Map<ArbitraryProperty, Object> combinedPropertyValuesByArbitraryProperty = new HashMap<>();
Expand All @@ -54,6 +55,7 @@ public T combined() {
return combinator.apply(combinedPropertyValuesByArbitraryProperty);
}

@SuppressWarnings({"return", "argument"})
@Override
public Object rawValue() {
Map<ArbitraryProperty, Object> rawPropertyValuesByArbitraryProperty = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public StringCombinableArbitrary filter(int tries, Predicate<String> predicate)
}

@Override
@SuppressWarnings("argument")
public StringCombinableArbitrary filterCharacter(int tries, Predicate<Character> predicate) {
return this.filter(tries, it -> it.chars().mapToObj(Character.class::cast).allMatch(predicate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class UniqueCombinableArbitrary<T> implements CombinableArbitrary<T> {
}

@Override
@SuppressWarnings("argument")
public T combined() {
return combinableArbitrary.filter(
it -> {
Expand All @@ -53,6 +54,7 @@ public T combined() {
}

@Override
@SuppressWarnings("argument")
public Object rawValue() {
return combinableArbitrary.filter(
it -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.jspecify.annotations.Nullable;

/**
* It is the Concurrent Least Recently Used cache.
Expand All @@ -32,8 +33,8 @@
* @param <K> key of the cache
* @param <V> value of the cache
*/
@SuppressWarnings("NullableProblems")
@API(since = "0.5.10", status = Status.MAINTAINED)
@SuppressWarnings({"contracts", "override", "return"})
public final class ConcurrentLruCache<K, V> implements Map<K, V> {
private final Map<K, V> lruCache;

Expand Down Expand Up @@ -62,7 +63,7 @@ public boolean containsValue(Object value) {
}

@Override
public V get(Object key) {
public @Nullable V get(Object key) {
return lruCache.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public DefaultDecomposedContainerValueFactory(
}

@Override
@SuppressWarnings("argument")
public DecomposableJavaContainer from(Object container) {
Class<?> actualType = container.getClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.jspecify.annotations.Nullable;

import com.navercorp.fixturemonkey.api.ObjectBuilder;
import com.navercorp.fixturemonkey.api.arbitrary.CombinableArbitrary;
Expand Down Expand Up @@ -69,7 +70,7 @@ public static MonkeyContextBuilder builder(FixtureMonkeyOptions fixtureMonkeyOpt
return new MonkeyContextBuilder(fixtureMonkeyOptions);
}

public CombinableArbitrary<?> getCachedArbitrary(Property property) {
public @Nullable CombinableArbitrary<?> getCachedArbitrary(Property property) {
CombinableArbitrary<?> javaTypeCombinableArbitrary = javaArbitrariesByProperty.get(property);
if (javaTypeCombinableArbitrary != null) {
return javaTypeCombinableArbitrary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.jspecify.annotations.Nullable;

import com.navercorp.fixturemonkey.api.generator.ArbitraryGeneratorContext;
import com.navercorp.fixturemonkey.api.property.PropertyPath;
Expand All @@ -40,7 +41,8 @@ public MonkeyGeneratorContext(SortedMap<PropertyPath, Set<Object>> uniqueSetsByP
this.uniqueSetsByProperty = uniqueSetsByProperty;
}

public synchronized boolean isUniqueAndCheck(PropertyPath property, Object value) {
@SuppressWarnings("argument")
public synchronized boolean isUniqueAndCheck(PropertyPath property, @Nullable Object value) {
Set<Object> set = uniqueSetsByProperty.computeIfAbsent(property, p -> new HashSet<>());
boolean unique = !set.contains(value);
if (unique) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@API(since = "0.4.0", status = Status.MAINTAINED)
@FunctionalInterface
public interface ExpressionGenerator extends PropertySelector {
@SuppressWarnings("nullness")
default String generate() {
return this.generate(Property::getName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public String resolveFieldName(Class<?> targetClass, String methodName) {
return null;
}

@Nullable
private static String stripPrefixPropertyName(Class<?> targetClass, String methodName, int prefixLength) {
char[] ch = methodName.toCharArray();
ch[prefixLength] = Character.toLowerCase(ch[prefixLength]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class JavaGetterPropertySelectors {
/**
* It is for internal use only. It can be changed or removed at any time.
**/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "dereference.of.nullable", "argument"})
static <T, R> JavaGetterMethodPropertySelector<T, R> resolvePropertySelector(
JavaGetterMethodReference<T, R> methodRef
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class ArbitraryGeneratorContext implements Traceable {
private final BiFunction<ArbitraryGeneratorContext, ArbitraryProperty, CombinableArbitrary<?>> resolveArbitrary;
private final MonkeyGeneratorContext monkeyGeneratorContext;
private final LazyArbitrary<PropertyPath> lazyPropertyPath;
@SuppressWarnings("methodref.receiver.bound")
private final LazyArbitrary<Map<ArbitraryProperty, CombinableArbitrary<?>>> arbitraryListByArbitraryProperty =
LazyArbitrary.lazy(this::initArbitraryListByArbitraryProperty);
private final int generateUniqueMaxTries;
Expand Down Expand Up @@ -124,6 +125,7 @@ public Map<String, CombinableArbitrary<?>> getCombinableArbitrariesByResolvedNam
.collect(toMap(it -> it.getKey().getObjectProperty().getResolvedPropertyName(), Entry::getValue));
}

@SuppressWarnings("return")
public Map<String, CombinableArbitrary<?>> getCombinableArbitrariesByPropertyName() {
return arbitraryListByArbitraryProperty.getValue().entrySet().stream()
.collect(toMap(it -> it.getKey().getObjectProperty().getProperty().getName(), Entry::getValue));
Expand All @@ -142,7 +144,7 @@ public boolean isRootContext() {
return this.property.getObjectProperty().isRoot();
}

public synchronized boolean isUniqueAndCheck(PropertyPath property, Object value) {
public synchronized boolean isUniqueAndCheck(PropertyPath property, @Nullable Object value) {
return monkeyGeneratorContext.isUniqueAndCheck(property, value);
}

Expand Down
Loading
Loading