Compare commits

...

17 Commits

Author SHA1 Message Date
Stephan Schroevers
2356c61314 [maven-release-plugin] prepare release v0.7.0 2023-01-06 11:29:09 +01:00
Stephan Schroevers
9a9ef3c59d Have apply-error-prone-suggestions.sh download JitPack-hosted artifacts (#441)
While there, tweak the usage message of both `apply-error-prone-suggestions.sh`
and `run-mutation-tests.sh`.
2023-01-06 10:38:54 +01:00
Rick Ossendrijver
e9a1d54035 Add @OnlineDocumentation to TestNGToAssertJRules (#447) 2023-01-06 10:28:21 +01:00
Picnic-Bot
e9733f7426 Upgrade AssertJ Core 3.23.1 -> 3.24.0 (#448)
While there, use the new BOM.

See:
- https://assertj.github.io/doc/#assertj-core-release-notes
- https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.23.1...assertj-build-3.24.0
2023-01-06 09:12:29 +01:00
Picnic-Bot
534ebb62a1 Upgrade Checker Framework Annotations 3.28.0 -> 3.29.0 (#449)
See:
- https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.29.0
- https://github.com/typetools/checker-framework/compare/checker-framework-3.28.0...checker-framework-3.29.0
2023-01-06 08:40:54 +01:00
Rick Ossendrijver
1ed1e6cd03 Update year to 2023 in footer_custom.html and LICENSE.md (#446) 2023-01-05 14:47:26 +01:00
Picnic-Bot
85e3db6f0a Upgrade pitest-maven-plugin 1.10.3 -> 1.10.4 (#445)
See:
- https://github.com/hcoles/pitest/releases/tag/1.10.4
- https://github.com/hcoles/pitest/compare/1.10.3...1.10.4
2023-01-05 09:58:06 +01:00
Picnic-Bot
6f4db8fc4d Upgrade NullAway 0.10.6 -> 0.10.7 (#444)
See:
- https://github.com/uber/NullAway/blob/master/CHANGELOG.md
- https://github.com/uber/NullAway/compare/v0.10.6...v0.10.7
2023-01-05 08:32:46 +01:00
chamil-prabodha
9d08e8fd4d Have RequestParamType ignore parameter types with custom deserialization support (#426)
While there, introduce and use a new `Flags` utility class; various checks'
list flags now better support empty lists.
2023-01-04 11:13:44 +01:00
Picnic-Bot
9992ff49ce Upgrade pitest-junit5-plugin 1.1.0 -> 1.1.1 (#440)
See https://github.com/pitest/pitest-junit5-plugin/compare/1.1.0...1.1.1
2023-01-04 10:21:44 +01:00
jarmilakaiser
190b47870b Show original Cody in README and on website home page (#438)
This reverts commit 0153c1495f.
2023-01-04 09:27:21 +01:00
Stephan Schroevers
becfcb5374 Upgrade Error Prone 2.16 -> 2.17.0 (#432)
See:
- https://github.com/google/error-prone/releases/tag/v2.17.0
- https://github.com/google/error-prone/compare/v2.16...v2.17.0
- https://github.com/PicnicSupermarket/error-prone/compare/v2.16-picnic-2...v2.17.0-picnic-1
2023-01-03 13:47:21 +01:00
Benedek Halasi
d45682143d Introduce/extend RequireNonNullElse{,Get} Refaster rules (#425)
Fixes #364.
2023-01-02 10:25:10 +01:00
Picnic-Bot
4237732c5b Upgrade errorprone-slf4j 0.1.16 -> 0.1.17 (#433)
See:
- https://github.com/KengoTODA/errorprone-slf4j/releases/tag/v0.1.17
- https://github.com/KengoTODA/errorprone-slf4j/compare/v0.1.16...v0.1.17
2023-01-02 10:04:51 +01:00
Picnic-Bot
d7c86c4854 Upgrade Checkstyle 10.5.0 -> 10.6.0 (#435)
See:
- https://checkstyle.sourceforge.io/releasenotes.html
- https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.6.0
- https://github.com/checkstyle/checkstyle/compare/checkstyle-10.5.0...checkstyle-10.6.0
2023-01-02 09:33:21 +01:00
Christos Giallouros
e6e50717d3 Introduce JUnitToAssertJRules Refaster rule collection (#417) 2023-01-02 08:51:46 +01:00
Picnic-Bot
834f9ae49b Upgrade NullAway 0.10.5 -> 0.10.6 (#429)
See:
- https://github.com/uber/NullAway/blob/master/CHANGELOG.md
- https://github.com/uber/NullAway/compare/v0.10.5...v0.10.6
2022-12-30 12:22:12 +01:00
29 changed files with 1141 additions and 551 deletions

View File

@@ -22,11 +22,10 @@ jobs:
jdk: 17.0.4
distribution: temurin
experimental: false
# XXX: Re-enable this build after upgrading to Error Prone 2.17.
#- os: ubuntu-22.04
# jdk: 20-ea
# distribution: zulu
# experimental: true
- os: ubuntu-22.04
jdk: 20-ea
distribution: zulu
experimental: true
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
steps:

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2022 Picnic Technologies BV
Copyright (c) 2017-2023 Picnic Technologies BV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -9,13 +9,14 @@
set -e -u -o pipefail
if [ "${#}" -gt 1 ]; then
echo "Usage: ./$(basename "${0}") [PatchChecks]"
echo "Usage: ${0} [PatchChecks]"
exit 1
fi
patchChecks=${1:-}
mvn clean test-compile fmt:format \
-s "$(dirname "${0}")/settings.xml" \
-T 1.0C \
-Perror-prone \
-Perror-prone-fork \

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
</parent>
<artifactId>error-prone-contrib</artifactId>
@@ -146,7 +146,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>

View File

@@ -42,6 +42,7 @@ import java.util.Set;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import tech.picnic.errorprone.bugpatterns.util.AnnotationAttributeMatcher;
import tech.picnic.errorprone.bugpatterns.util.Flags;
import tech.picnic.errorprone.bugpatterns.util.SourceCode;
/**
@@ -220,7 +221,7 @@ public final class LexicographicalAnnotationAttributeListing extends BugChecker
private static ImmutableList<String> excludedAnnotations(ErrorProneFlags flags) {
Set<String> exclusions = new HashSet<>();
flags.getList(EXCLUDED_ANNOTATIONS_FLAG).ifPresent(exclusions::addAll);
exclusions.addAll(Flags.getList(flags, EXCLUDED_ANNOTATIONS_FLAG));
exclusions.addAll(BLACKLISTED_ANNOTATIONS);
return ImmutableList.copyOf(exclusions);
}

View File

@@ -49,6 +49,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import tech.picnic.errorprone.bugpatterns.util.Flags;
import tech.picnic.errorprone.bugpatterns.util.MethodMatcherFactory;
import tech.picnic.errorprone.bugpatterns.util.SourceCode;
@@ -63,9 +64,8 @@ import tech.picnic.errorprone.bugpatterns.util.SourceCode;
public final class RedundantStringConversion extends BugChecker
implements BinaryTreeMatcher, CompoundAssignmentTreeMatcher, MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final String FLAG_PREFIX = "RedundantStringConversion:";
private static final String EXTRA_STRING_CONVERSION_METHODS_FLAG =
FLAG_PREFIX + "ExtraConversionMethods";
"RedundantStringConversion:ExtraConversionMethods";
@SuppressWarnings("UnnecessaryLambda")
private static final Matcher<ExpressionTree> ANY_EXPR = (t, s) -> true;
@@ -374,10 +374,9 @@ public final class RedundantStringConversion extends BugChecker
ErrorProneFlags flags) {
// XXX: ErrorProneFlags#getList splits by comma, but method signatures may also contain commas.
// For this class methods accepting more than one argument are not valid, but still: not nice.
return flags
.getList(EXTRA_STRING_CONVERSION_METHODS_FLAG)
.map(new MethodMatcherFactory()::create)
.map(m -> anyOf(WELL_KNOWN_STRING_CONVERSION_METHODS, m))
.orElse(WELL_KNOWN_STRING_CONVERSION_METHODS);
return anyOf(
WELL_KNOWN_STRING_CONVERSION_METHODS,
new MethodMatcherFactory()
.create(Flags.getList(flags, EXTRA_STRING_CONVERSION_METHODS_FLAG)));
}
}

View File

@@ -1,5 +1,6 @@
package tech.picnic.errorprone.bugpatterns;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.errorprone.BugPattern.LinkType.CUSTOM;
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR;
@@ -9,41 +10,72 @@ import static com.google.errorprone.matchers.Matchers.annotations;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.isSubtypeOf;
import static com.google.errorprone.matchers.Matchers.isType;
import static com.google.errorprone.matchers.Matchers.not;
import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL;
import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.BugPattern;
import com.google.errorprone.ErrorProneFlags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.suppliers.Suppliers;
import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import tech.picnic.errorprone.bugpatterns.util.Flags;
/** A {@link BugChecker} that flags {@code @RequestParam} parameters with an unsupported type. */
@AutoService(BugChecker.class)
@BugPattern(
summary = "`@RequestParam` does not support `ImmutableCollection` and `ImmutableMap` subtypes",
summary =
"By default, `@RequestParam` does not support `ImmutableCollection` and `ImmutableMap` subtypes",
link = BUG_PATTERNS_BASE_URL + "RequestParamType",
linkType = CUSTOM,
severity = ERROR,
tags = LIKELY_ERROR)
public final class RequestParamType extends BugChecker implements VariableTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<VariableTree> HAS_UNSUPPORTED_REQUEST_PARAM =
allOf(
annotations(AT_LEAST_ONE, isType("org.springframework.web.bind.annotation.RequestParam")),
anyOf(isSubtypeOf(ImmutableCollection.class), isSubtypeOf(ImmutableMap.class)));
private static final String SUPPORTED_CUSTOM_TYPES_FLAG = "RequestParamType:SupportedCustomTypes";
/** Instantiates a new {@link RequestParamType} instance. */
public RequestParamType() {}
private final Matcher<VariableTree> hasUnsupportedRequestParamType;
/** Instantiates a default {@link RequestParamType} instance. */
public RequestParamType() {
this(ErrorProneFlags.empty());
}
/**
* Instantiates a customized {@link RequestParamType} instance.
*
* @param flags Any provided command line flags.
*/
public RequestParamType(ErrorProneFlags flags) {
hasUnsupportedRequestParamType = hasUnsupportedRequestParamType(flags);
}
@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
return HAS_UNSUPPORTED_REQUEST_PARAM.matches(tree, state)
return hasUnsupportedRequestParamType.matches(tree, state)
? describeMatch(tree)
: Description.NO_MATCH;
}
private static Matcher<VariableTree> hasUnsupportedRequestParamType(ErrorProneFlags flags) {
return allOf(
annotations(AT_LEAST_ONE, isType("org.springframework.web.bind.annotation.RequestParam")),
anyOf(isSubtypeOf(ImmutableCollection.class), isSubtypeOf(ImmutableMap.class)),
not(isSubtypeOfAny(Flags.getList(flags, SUPPORTED_CUSTOM_TYPES_FLAG))));
}
private static Matcher<Tree> isSubtypeOfAny(ImmutableList<String> inclusions) {
return anyOf(
inclusions.stream()
.map(inclusion -> isSubtypeOf(Suppliers.typeFromString(inclusion)))
.collect(toImmutableList()));
}
}

View File

@@ -0,0 +1,25 @@
package tech.picnic.errorprone.bugpatterns.util;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.ErrorProneFlags;
/** Helper methods for working with {@link ErrorProneFlags}. */
public final class Flags {
private Flags() {}
/**
* Returns the list of (comma-separated) arguments passed using the given Error Prone flag.
*
* @param errorProneFlags The full set of flags provided.
* @param name The name of the flag of interest.
* @return A non-{@code null} list of provided arguments; this list is empty if the flag was not
* provided, or if the flag's value is the empty string.
*/
public static ImmutableList<String> getList(ErrorProneFlags errorProneFlags, String name) {
return errorProneFlags
.getList(name)
.map(ImmutableList::copyOf)
.filter(flags -> !flags.equals(ImmutableList.of("")))
.orElseGet(ImmutableList::of);
}
}

View File

@@ -22,7 +22,6 @@ final class AssertJOptionalRules {
static final class AssertThatOptional<T> {
@BeforeTemplate
@SuppressWarnings("NullAway")
ObjectAssert<T> before(Optional<T> optional) {
return assertThat(optional.orElseThrow());
}

View File

@@ -0,0 +1,521 @@
package tech.picnic.errorprone.refasterrules;
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.DoNotCall;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import java.util.function.Supplier;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.function.ThrowingSupplier;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
/**
* Refaster rules to replace JUnit assertions with AssertJ equivalents.
*
* <p>Note that, while both libraries throw an {@link AssertionError} in case of an assertion
* failure, the exact subtype used generally differs.
*/
// XXX: Not all `org.assertj.core.api.Assertions` methods have an associated Refaster rule yet;
// expand this class.
// XXX: Introduce a `@Matcher` on `Executable` and `ThrowingSupplier` expressions, such that they
// are only matched if they are also compatible with the `ThrowingCallable` functional interface.
// When implementing such a matcher, note that expressions with a non-void return type such as
// `() -> toString()` match both `ThrowingSupplier` and `ThrowingCallable`, but `() -> "constant"`
// is only compatible with the former.
@OnlineDocumentation
final class JUnitToAssertJRules {
private JUnitToAssertJRules() {}
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(
Assertions.class,
assertDoesNotThrow(() -> null),
assertInstanceOf(null, null),
assertThrows(null, null),
assertThrowsExactly(null, null),
(Runnable) () -> assertFalse(true),
(Runnable) () -> assertNotNull(null),
(Runnable) () -> assertNotSame(null, null),
(Runnable) () -> assertNull(null),
(Runnable) () -> assertSame(null, null),
(Runnable) () -> assertTrue(true));
}
static final class ThrowNewAssertionError {
@BeforeTemplate
void before() {
Assertions.fail();
}
@AfterTemplate
@DoNotCall
void after() {
throw new AssertionError();
}
}
static final class FailWithMessage<T> {
@BeforeTemplate
T before(String message) {
return Assertions.fail(message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
T after(String message) {
return fail(message);
}
}
static final class FailWithMessageAndThrowable<T> {
@BeforeTemplate
T before(String message, Throwable throwable) {
return Assertions.fail(message, throwable);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
T after(String message, Throwable throwable) {
return fail(message, throwable);
}
}
static final class FailWithThrowable {
@BeforeTemplate
void before(Throwable throwable) {
Assertions.fail(throwable);
}
@AfterTemplate
@DoNotCall
void after(Throwable throwable) {
throw new AssertionError(throwable);
}
}
static final class AssertThatIsTrue {
@BeforeTemplate
void before(boolean actual) {
assertTrue(actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual) {
assertThat(actual).isTrue();
}
}
static final class AssertThatWithFailMessageStringIsTrue {
@BeforeTemplate
void before(boolean actual, String message) {
assertTrue(actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual, String message) {
assertThat(actual).withFailMessage(message).isTrue();
}
}
static final class AssertThatWithFailMessageSupplierIsTrue {
@BeforeTemplate
void before(boolean actual, Supplier<String> supplier) {
assertTrue(actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isTrue();
}
}
static final class AssertThatIsFalse {
@BeforeTemplate
void before(boolean actual) {
assertFalse(actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual) {
assertThat(actual).isFalse();
}
}
static final class AssertThatWithFailMessageStringIsFalse {
@BeforeTemplate
void before(boolean actual, String message) {
assertFalse(actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual, String message) {
assertThat(actual).withFailMessage(message).isFalse();
}
}
static final class AssertThatWithFailMessageSupplierIsFalse {
@BeforeTemplate
void before(boolean actual, Supplier<String> supplier) {
assertFalse(actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(boolean actual, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isFalse();
}
}
static final class AssertThatIsNull {
@BeforeTemplate
void before(Object actual) {
assertNull(actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual) {
assertThat(actual).isNull();
}
}
static final class AssertThatWithFailMessageStringIsNull {
@BeforeTemplate
void before(Object actual, String message) {
assertNull(actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, String message) {
assertThat(actual).withFailMessage(message).isNull();
}
}
static final class AssertThatWithFailMessageSupplierIsNull {
@BeforeTemplate
void before(Object actual, Supplier<String> supplier) {
assertNull(actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isNull();
}
}
static final class AssertThatIsNotNull {
@BeforeTemplate
void before(Object actual) {
assertNotNull(actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual) {
assertThat(actual).isNotNull();
}
}
static final class AssertThatWithFailMessageStringIsNotNull {
@BeforeTemplate
void before(Object actual, String message) {
assertNotNull(actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, String message) {
assertThat(actual).withFailMessage(message).isNotNull();
}
}
static final class AssertThatWithFailMessageSupplierIsNotNull {
@BeforeTemplate
void before(Object actual, Supplier<String> supplier) {
assertNotNull(actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isNotNull();
}
}
static final class AssertThatIsSameAs {
@BeforeTemplate
void before(Object actual, Object expected) {
assertSame(expected, actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected) {
assertThat(actual).isSameAs(expected);
}
}
static final class AssertThatWithFailMessageStringIsSameAs {
@BeforeTemplate
void before(Object actual, Object expected, String message) {
assertSame(expected, actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected, String message) {
assertThat(actual).withFailMessage(message).isSameAs(expected);
}
}
static final class AssertThatWithFailMessageSupplierIsSameAs {
@BeforeTemplate
void before(Object actual, Object expected, Supplier<String> supplier) {
assertSame(expected, actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isSameAs(expected);
}
}
static final class AssertThatIsNotSameAs {
@BeforeTemplate
void before(Object actual, Object expected) {
assertNotSame(expected, actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected) {
assertThat(actual).isNotSameAs(expected);
}
}
static final class AssertThatWithFailMessageStringIsNotSameAs {
@BeforeTemplate
void before(Object actual, Object expected, String message) {
assertNotSame(expected, actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected, String message) {
assertThat(actual).withFailMessage(message).isNotSameAs(expected);
}
}
static final class AssertThatWithFailMessageSupplierIsNotSameAs {
@BeforeTemplate
void before(Object actual, Object expected, Supplier<String> supplier) {
assertNotSame(expected, actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Object expected, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isNotSameAs(expected);
}
}
static final class AssertThatThrownByIsExactlyInstanceOf<T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz) {
assertThrowsExactly(clazz, throwingCallable);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz) {
assertThatThrownBy(throwingCallable).isExactlyInstanceOf(clazz);
}
}
static final class AssertThatThrownByWithFailMessageStringIsExactlyInstanceOf<
T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz, String message) {
assertThrowsExactly(clazz, throwingCallable, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz, String message) {
assertThatThrownBy(throwingCallable).withFailMessage(message).isExactlyInstanceOf(clazz);
}
}
static final class AssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf<
T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz, Supplier<String> supplier) {
assertThrowsExactly(clazz, throwingCallable, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz, Supplier<String> supplier) {
assertThatThrownBy(throwingCallable).withFailMessage(supplier).isExactlyInstanceOf(clazz);
}
}
static final class AssertThatThrownByIsInstanceOf<T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz) {
assertThrows(clazz, throwingCallable);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz) {
assertThatThrownBy(throwingCallable).isInstanceOf(clazz);
}
}
static final class AssertThatThrownByWithFailMessageStringIsInstanceOf<T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz, String message) {
assertThrows(clazz, throwingCallable, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz, String message) {
assertThatThrownBy(throwingCallable).withFailMessage(message).isInstanceOf(clazz);
}
}
static final class AssertThatThrownByWithFailMessageSupplierIsInstanceOf<T extends Throwable> {
@BeforeTemplate
void before(Executable throwingCallable, Class<T> clazz, Supplier<String> supplier) {
assertThrows(clazz, throwingCallable, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Class<T> clazz, Supplier<String> supplier) {
assertThatThrownBy(throwingCallable).withFailMessage(supplier).isInstanceOf(clazz);
}
}
static final class AssertThatCodeDoesNotThrowAnyException {
@BeforeTemplate
void before(Executable throwingCallable) {
assertDoesNotThrow(throwingCallable);
}
@BeforeTemplate
void before(ThrowingSupplier<?> throwingCallable) {
assertDoesNotThrow(throwingCallable);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable) {
assertThatCode(throwingCallable).doesNotThrowAnyException();
}
}
static final class AssertThatCodeWithFailMessageStringDoesNotThrowAnyException {
@BeforeTemplate
void before(Executable throwingCallable, String message) {
assertDoesNotThrow(throwingCallable, message);
}
@BeforeTemplate
void before(ThrowingSupplier<?> throwingCallable, String message) {
assertDoesNotThrow(throwingCallable, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, String message) {
assertThatCode(throwingCallable).withFailMessage(message).doesNotThrowAnyException();
}
}
static final class AssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException {
@BeforeTemplate
void before(Executable throwingCallable, Supplier<String> supplier) {
assertDoesNotThrow(throwingCallable, supplier);
}
@BeforeTemplate
void before(ThrowingSupplier<?> throwingCallable, Supplier<String> supplier) {
assertDoesNotThrow(throwingCallable, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(ThrowingCallable throwingCallable, Supplier<String> supplier) {
assertThatCode(throwingCallable).withFailMessage(supplier).doesNotThrowAnyException();
}
}
static final class AssertThatIsInstanceOf<T> {
@BeforeTemplate
void before(Object actual, Class<T> clazz) {
assertInstanceOf(clazz, actual);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Class<T> clazz) {
assertThat(actual).isInstanceOf(clazz);
}
}
static final class AssertThatWithFailMessageStringIsInstanceOf<T> {
@BeforeTemplate
void before(Object actual, Class<T> clazz, String message) {
assertInstanceOf(clazz, actual, message);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Class<T> clazz, String message) {
assertThat(actual).withFailMessage(message).isInstanceOf(clazz);
}
}
static final class AssertThatWithFailMessageSupplierIsInstanceOf<T> {
@BeforeTemplate
void before(Object actual, Class<T> clazz, Supplier<String> supplier) {
assertInstanceOf(clazz, actual, supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(Object actual, Class<T> clazz, Supplier<String> supplier) {
assertThat(actual).withFailMessage(supplier).isInstanceOf(clazz);
}
}
}

View File

@@ -2,13 +2,17 @@ package tech.picnic.errorprone.refasterrules;
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static java.util.Objects.requireNonNullElse;
import static java.util.Objects.requireNonNullElseGet;
import com.google.common.base.MoreObjects;
import com.google.errorprone.refaster.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
@@ -43,13 +47,18 @@ final class NullRules {
}
}
/** Prefer {@link Objects#requireNonNullElse(Object, Object)} over the Guava alternative. */
// XXX: This rule is not valid in case `second` is `@Nullable`: in that case the Guava variant
// will return `null`, while the JDK variant will throw an NPE.
/**
* Prefer {@link Objects#requireNonNullElse(Object, Object)} over non-JDK or more contrived
* alternatives.
*/
// XXX: This rule is not valid in case `second` is `@Nullable`: in that case the Guava and
// `Optional` variants will return `null`, where the `requireNonNullElse` alternative will throw
// an NPE.
static final class RequireNonNullElse<T> {
@BeforeTemplate
T before(T first, T second) {
return MoreObjects.firstNonNull(first, second);
return Refaster.anyOf(
MoreObjects.firstNonNull(first, second), Optional.ofNullable(first).orElse(second));
}
@AfterTemplate
@@ -59,6 +68,26 @@ final class NullRules {
}
}
/**
* Prefer {@link Objects#requireNonNullElseGet(Object, Supplier)} over more contrived
* alternatives.
*/
// XXX: This rule is not valid in case `supplier` yields `@Nullable` values: in that case the
// `Optional` variant will return `null`, where the `requireNonNullElseGet` alternative will throw
// an NPE.
static final class RequireNonNullElseGet<T, S extends T> {
@BeforeTemplate
T before(T object, Supplier<S> supplier) {
return Optional.ofNullable(object).orElseGet(supplier);
}
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
T after(T object, Supplier<S> supplier) {
return requireNonNullElseGet(object, supplier);
}
}
/** Prefer {@link Objects#isNull(Object)} over the equivalent lambda function. */
static final class IsNullFunction<T> {
@BeforeTemplate

View File

@@ -372,10 +372,7 @@ final class ReactorRules {
return mono.switchIfEmpty(Mono.empty());
}
// XXX: Review the suppression once NullAway has better support for generics. Keep an eye on
// https://github.com/uber/NullAway/issues?q=is%3Aopen+generics.
@BeforeTemplate
@SuppressWarnings("NullAway" /* False positive. */)
Mono<@Nullable Void> before2(Mono<@Nullable Void> mono) {
return mono.then();
}

View File

@@ -28,6 +28,7 @@ import java.util.Set;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.testng.Assert;
import org.testng.Assert.ThrowingRunnable;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
/**
* Refaster rules that replace TestNG assertions with equivalent AssertJ assertions.
@@ -72,6 +73,7 @@ import org.testng.Assert.ThrowingRunnable;
// XXX: As-is these rules do not result in a complete migration:
// - Expressions containing comments are skipped due to a limitation of Refaster.
// - Assertions inside lambda expressions are also skipped. Unclear why.
@OnlineDocumentation
final class TestNGToAssertJRules {
private TestNGToAssertJRules() {}

View File

@@ -6,6 +6,10 @@ import org.junit.jupiter.api.Test;
final class RequestParamTypeTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(RequestParamType.class, getClass());
private final CompilationTestHelper restrictedCompilationTestHelper =
CompilationTestHelper.newInstance(RequestParamType.class, getClass())
.setArgs(
"-XepOpt:RequestParamType:SupportedCustomTypes=com.google.common.collect.ImmutableSet,com.google.common.collect.ImmutableSortedMultiset");
@Test
void identification() {
@@ -63,4 +67,53 @@ final class RequestParamTypeTest {
"}")
.doTest();
}
@Test
void identificationRestricted() {
restrictedCompilationTestHelper
.addSourceLines(
"A.java",
"import com.google.common.collect.ImmutableBiMap;",
"import com.google.common.collect.ImmutableCollection;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableMap;",
"import com.google.common.collect.ImmutableMultiset;",
"import com.google.common.collect.ImmutableSet;",
"import com.google.common.collect.ImmutableSortedMultiset;",
"import com.google.common.collect.ImmutableSortedSet;",
"import org.springframework.web.bind.annotation.GetMapping;",
"import org.springframework.web.bind.annotation.RequestParam;",
"",
"interface A {",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A immutableCollection(@RequestParam ImmutableCollection<String> param);",
"",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A immutableList(@RequestParam ImmutableList<String> param);",
"",
" @GetMapping",
" A immutableSet(@RequestParam ImmutableSet<String> param);",
"",
" @GetMapping",
" A immutableSortedSet(@RequestParam ImmutableSortedSet<String> param);",
"",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A immutableMultiset(@RequestParam ImmutableMultiset<String> param);",
"",
" @GetMapping",
" A immutableSortedMultiset(@RequestParam ImmutableSortedMultiset<String> param);",
"",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A immutableMap(@RequestParam ImmutableMap<String, String> param);",
"",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A immutableBiMap(@RequestParam ImmutableBiMap<String, String> param);",
"}")
.doTest();
}
}

View File

@@ -0,0 +1,31 @@
package tech.picnic.errorprone.bugpatterns.util;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.ErrorProneOptions;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
final class FlagsTest {
private static Stream<Arguments> getListTestCases() {
/* { args, flag, expected } */
return Stream.of(
arguments(ImmutableList.of(), "Foo", ImmutableList.of()),
arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Qux", ImmutableList.of()),
arguments(ImmutableList.of("-XepOpt:Foo="), "Foo", ImmutableList.of()),
arguments(ImmutableList.of("-XepOpt:Foo=bar"), "Foo", ImmutableList.of("bar")),
arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Foo", ImmutableList.of("bar", "baz")),
arguments(ImmutableList.of("-XepOpt:Foo=,"), "Foo", ImmutableList.of("", "")));
}
@MethodSource("getListTestCases")
@ParameterizedTest
void getList(ImmutableList<String> args, String flag, ImmutableList<String> expected) {
assertThat(Flags.getList(ErrorProneOptions.processArgs(args).getFlags(), flag))
.containsExactlyElementsOf(expected);
}
}

View File

@@ -50,6 +50,7 @@ final class RefasterRulesTest {
ImmutableSortedSetRules.class,
IntStreamRules.class,
JUnitRules.class,
JUnitToAssertJRules.class,
LongStreamRules.class,
MapEntryRules.class,
MapRules.class,

View File

@@ -0,0 +1,173 @@
package tech.picnic.errorprone.refasterrules;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Assertions;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(
Assertions.class,
assertDoesNotThrow(() -> null),
assertInstanceOf(null, null),
assertThrows(null, null),
assertThrowsExactly(null, null),
(Runnable) () -> assertFalse(true),
(Runnable) () -> assertNotNull(null),
(Runnable) () -> assertNotSame(null, null),
(Runnable) () -> assertNull(null),
(Runnable) () -> assertSame(null, null),
(Runnable) () -> assertTrue(true));
}
void testThrowNewAssertionError() {
Assertions.fail();
}
Object testFailWithMessage() {
return Assertions.fail("foo");
}
Object testFailWithMessageAndThrowable() {
return Assertions.fail("foo", new IllegalStateException());
}
void testFailWithThrowable() {
Assertions.fail(new IllegalStateException());
}
void testAssertThatIsTrue() {
assertTrue(true);
}
void testAssertThatWithFailMessageStringIsTrue() {
assertTrue(true, "foo");
}
void testAssertThatWithFailMessageSupplierIsTrue() {
assertTrue(true, () -> "foo");
}
void testAssertThatIsFalse() {
assertFalse(true);
}
void testAssertThatWithFailMessageStringIsFalse() {
assertFalse(true, "foo");
}
void testAssertThatWithFailMessageSupplierIsFalse() {
assertFalse(true, () -> "foo");
}
void testAssertThatIsNull() {
assertNull(new Object());
}
void testAssertThatWithFailMessageStringIsNull() {
assertNull(new Object(), "foo");
}
void testAssertThatWithFailMessageSupplierIsNull() {
assertNull(new Object(), () -> "foo");
}
void testAssertThatIsNotNull() {
assertNotNull(new Object());
}
void testAssertThatWithFailMessageStringIsNotNull() {
assertNotNull(new Object(), "foo");
}
void testAssertThatWithFailMessageSupplierIsNotNull() {
assertNotNull(new Object(), () -> "foo");
}
void testAssertThatIsSameAs() {
assertSame("foo", "bar");
}
void testAssertThatWithFailMessageStringIsSameAs() {
assertSame("foo", "bar", "baz");
}
void testAssertThatWithFailMessageSupplierIsSameAs() {
assertSame("foo", "bar", () -> "baz");
}
void testAssertThatIsNotSameAs() {
assertNotSame("foo", "bar");
}
void testAssertThatWithFailMessageStringIsNotSameAs() {
assertNotSame("foo", "bar", "baz");
}
void testAssertThatWithFailMessageSupplierIsNotSameAs() {
assertNotSame("foo", "bar", () -> "baz");
}
void testAssertThatThrownByIsExactlyInstanceOf() {
assertThrowsExactly(IllegalStateException.class, () -> {});
}
void testAssertThatThrownByWithFailMessageStringIsExactlyInstanceOf() {
assertThrowsExactly(IllegalStateException.class, () -> {}, "foo");
}
void testAssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf() {
assertThrowsExactly(IllegalStateException.class, () -> {}, () -> "foo");
}
void testAssertThatThrownByIsInstanceOf() {
assertThrows(IllegalStateException.class, () -> {});
}
void testAssertThatThrownByWithFailMessageStringIsInstanceOf() {
assertThrows(IllegalStateException.class, () -> {}, "foo");
}
void testAssertThatThrownByWithFailMessageSupplierIsInstanceOf() {
assertThrows(IllegalStateException.class, () -> {}, () -> "foo");
}
void testAssertThatCodeDoesNotThrowAnyException() {
assertDoesNotThrow(() -> {});
assertDoesNotThrow(() -> toString());
}
void testAssertThatCodeWithFailMessageStringDoesNotThrowAnyException() {
assertDoesNotThrow(() -> {}, "foo");
assertDoesNotThrow(() -> toString(), "bar");
}
void testAssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException() {
assertDoesNotThrow(() -> {}, () -> "foo");
assertDoesNotThrow(() -> toString(), () -> "bar");
}
void testAssertThatIsInstanceOf() {
assertInstanceOf(Object.class, new Object());
}
void testAssertThatWithFailMessageStringIsInstanceOf() {
assertInstanceOf(Object.class, new Object(), "foo");
}
void testAssertThatWithFailMessageSupplierIsInstanceOf() {
assertInstanceOf(Object.class, new Object(), () -> "foo");
}
}

View File

@@ -0,0 +1,183 @@
package tech.picnic.errorprone.refasterrules;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Assertions;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(
Assertions.class,
assertDoesNotThrow(() -> null),
assertInstanceOf(null, null),
assertThrows(null, null),
assertThrowsExactly(null, null),
(Runnable) () -> assertFalse(true),
(Runnable) () -> assertNotNull(null),
(Runnable) () -> assertNotSame(null, null),
(Runnable) () -> assertNull(null),
(Runnable) () -> assertSame(null, null),
(Runnable) () -> assertTrue(true));
}
void testThrowNewAssertionError() {
throw new AssertionError();
}
Object testFailWithMessage() {
return fail("foo");
}
Object testFailWithMessageAndThrowable() {
return fail("foo", new IllegalStateException());
}
void testFailWithThrowable() {
throw new AssertionError(new IllegalStateException());
}
void testAssertThatIsTrue() {
assertThat(true).isTrue();
}
void testAssertThatWithFailMessageStringIsTrue() {
assertThat(true).withFailMessage("foo").isTrue();
}
void testAssertThatWithFailMessageSupplierIsTrue() {
assertThat(true).withFailMessage(() -> "foo").isTrue();
}
void testAssertThatIsFalse() {
assertThat(true).isFalse();
}
void testAssertThatWithFailMessageStringIsFalse() {
assertThat(true).withFailMessage("foo").isFalse();
}
void testAssertThatWithFailMessageSupplierIsFalse() {
assertThat(true).withFailMessage(() -> "foo").isFalse();
}
void testAssertThatIsNull() {
assertThat(new Object()).isNull();
}
void testAssertThatWithFailMessageStringIsNull() {
assertThat(new Object()).withFailMessage("foo").isNull();
}
void testAssertThatWithFailMessageSupplierIsNull() {
assertThat(new Object()).withFailMessage(() -> "foo").isNull();
}
void testAssertThatIsNotNull() {
assertThat(new Object()).isNotNull();
}
void testAssertThatWithFailMessageStringIsNotNull() {
assertThat(new Object()).withFailMessage("foo").isNotNull();
}
void testAssertThatWithFailMessageSupplierIsNotNull() {
assertThat(new Object()).withFailMessage(() -> "foo").isNotNull();
}
void testAssertThatIsSameAs() {
assertThat("bar").isSameAs("foo");
}
void testAssertThatWithFailMessageStringIsSameAs() {
assertThat("bar").withFailMessage("baz").isSameAs("foo");
}
void testAssertThatWithFailMessageSupplierIsSameAs() {
assertThat("bar").withFailMessage(() -> "baz").isSameAs("foo");
}
void testAssertThatIsNotSameAs() {
assertThat("bar").isNotSameAs("foo");
}
void testAssertThatWithFailMessageStringIsNotSameAs() {
assertThat("bar").withFailMessage("baz").isNotSameAs("foo");
}
void testAssertThatWithFailMessageSupplierIsNotSameAs() {
assertThat("bar").withFailMessage(() -> "baz").isNotSameAs("foo");
}
void testAssertThatThrownByIsExactlyInstanceOf() {
assertThatThrownBy(() -> {}).isExactlyInstanceOf(IllegalStateException.class);
}
void testAssertThatThrownByWithFailMessageStringIsExactlyInstanceOf() {
assertThatThrownBy(() -> {})
.withFailMessage("foo")
.isExactlyInstanceOf(IllegalStateException.class);
}
void testAssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf() {
assertThatThrownBy(() -> {})
.withFailMessage(() -> "foo")
.isExactlyInstanceOf(IllegalStateException.class);
}
void testAssertThatThrownByIsInstanceOf() {
assertThatThrownBy(() -> {}).isInstanceOf(IllegalStateException.class);
}
void testAssertThatThrownByWithFailMessageStringIsInstanceOf() {
assertThatThrownBy(() -> {}).withFailMessage("foo").isInstanceOf(IllegalStateException.class);
}
void testAssertThatThrownByWithFailMessageSupplierIsInstanceOf() {
assertThatThrownBy(() -> {})
.withFailMessage(() -> "foo")
.isInstanceOf(IllegalStateException.class);
}
void testAssertThatCodeDoesNotThrowAnyException() {
assertThatCode(() -> {}).doesNotThrowAnyException();
assertThatCode(() -> toString()).doesNotThrowAnyException();
}
void testAssertThatCodeWithFailMessageStringDoesNotThrowAnyException() {
assertThatCode(() -> {}).withFailMessage("foo").doesNotThrowAnyException();
assertThatCode(() -> toString()).withFailMessage("bar").doesNotThrowAnyException();
}
void testAssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException() {
assertThatCode(() -> {}).withFailMessage(() -> "foo").doesNotThrowAnyException();
assertThatCode(() -> toString()).withFailMessage(() -> "bar").doesNotThrowAnyException();
}
void testAssertThatIsInstanceOf() {
assertThat(new Object()).isInstanceOf(Object.class);
}
void testAssertThatWithFailMessageStringIsInstanceOf() {
assertThat(new Object()).withFailMessage("foo").isInstanceOf(Object.class);
}
void testAssertThatWithFailMessageSupplierIsInstanceOf() {
assertThat(new Object()).withFailMessage(() -> "foo").isInstanceOf(Object.class);
}
}

View File

@@ -3,13 +3,14 @@ package tech.picnic.errorprone.refasterrules;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class NullRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(MoreObjects.class);
return ImmutableSet.of(MoreObjects.class, Optional.class);
}
boolean testIsNull() {
@@ -20,8 +21,13 @@ final class NullRulesTest implements RefasterRuleCollectionTestCase {
return Objects.nonNull("foo");
}
String testRequireNonNullElse() {
return MoreObjects.firstNonNull("foo", "bar");
ImmutableSet<String> testRequireNonNullElse() {
return ImmutableSet.of(
MoreObjects.firstNonNull("foo", "bar"), Optional.ofNullable("baz").orElse("qux"));
}
String testRequireNonNullElseGet() {
return Optional.ofNullable("foo").orElseGet(() -> "bar");
}
long testIsNullFunction() {

View File

@@ -1,17 +1,19 @@
package tech.picnic.errorprone.refasterrules;
import static java.util.Objects.requireNonNullElse;
import static java.util.Objects.requireNonNullElseGet;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
final class NullRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(MoreObjects.class);
return ImmutableSet.of(MoreObjects.class, Optional.class);
}
boolean testIsNull() {
@@ -22,8 +24,12 @@ final class NullRulesTest implements RefasterRuleCollectionTestCase {
return "foo" != null;
}
String testRequireNonNullElse() {
return requireNonNullElse("foo", "bar");
ImmutableSet<String> testRequireNonNullElse() {
return ImmutableSet.of(requireNonNullElse("foo", "bar"), requireNonNullElse("baz", "qux"));
}
String testRequireNonNullElseGet() {
return requireNonNullElseGet("foo", () -> "bar");
}
long testIsNullFunction() {

34
pom.xml
View File

@@ -4,7 +4,7 @@
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
<packaging>pom</packaging>
<name>Picnic :: Error Prone Support</name>
@@ -48,7 +48,7 @@
<scm>
<developerConnection>scm:git:git@github.com:PicnicSupermarket/error-prone-support.git</developerConnection>
<tag>HEAD</tag>
<tag>v0.7.0</tag>
<url>https://github.com/PicnicSupermarket/error-prone-support</url>
</scm>
<issueManagement>
@@ -148,15 +148,15 @@
<version.auto-service>1.0.1</version.auto-service>
<version.auto-value>1.10.1</version.auto-value>
<version.error-prone>${version.error-prone-orig}</version.error-prone>
<version.error-prone-fork>v${version.error-prone-orig}-picnic-2</version.error-prone-fork>
<version.error-prone-orig>2.16</version.error-prone-orig>
<version.error-prone-slf4j>0.1.16</version.error-prone-slf4j>
<version.error-prone-fork>v${version.error-prone-orig}-picnic-1</version.error-prone-fork>
<version.error-prone-orig>2.17.0</version.error-prone-orig>
<version.error-prone-slf4j>0.1.17</version.error-prone-slf4j>
<version.guava-beta-checker>1.0</version.guava-beta-checker>
<version.jdk>11</version.jdk>
<version.maven>3.8.6</version.maven>
<version.mockito>4.11.0</version.mockito>
<version.nopen-checker>1.0.1</version.nopen-checker>
<version.nullaway>0.10.5</version.nullaway>
<version.nullaway>0.10.7</version.nullaway>
<version.pitest-git>1.0.3</version.pitest-git>
<version.surefire>2.22.2</version.surefire>
</properties>
@@ -337,13 +337,15 @@
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<artifactId>assertj-bom</artifactId>
<version>3.24.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>3.28.0</version>
<version>3.29.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
@@ -686,10 +688,6 @@
<!-- Instead, please use
`com.google.common.collect.Streams`. -->
</property>
<property name="illegalClasses" value="org\.junit\.jupiter\.api\.Assertions(\..*?)?">
<!-- Instead, please use
`org.assertj.core.api.Assertions`. -->
</property>
<property name="illegalClasses" value="org\.springframework\.stereotype\.(Component|Controller|Service)">
<!-- We don't use Spring's
component scanning, so `@Component`
@@ -771,7 +769,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.5.0</version>
<version>10.6.0</version>
</dependency>
<dependency>
<groupId>io.spring.nohttp</groupId>
@@ -1241,7 +1239,7 @@
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.10.3</version>
<version>1.10.4</version>
<configuration>
<excludedClasses>
<!-- AutoValue generated classes. -->
@@ -1280,7 +1278,7 @@
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
</dependencies>
<executions>
@@ -1594,6 +1592,10 @@
-XepOpt:NullAway:AssertsEnabled=true
-XepOpt:NullAway:CheckOptionalEmptiness=true
-XepOpt:Nullness:Conservative=false
<!-- XXX: Enable once this check respects
the compilation source version. See
https://github.com/google/error-prone/pull/3646.
-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true -->
<!-- Append additional custom arguments. -->
${error-prone.patch-args}
${error-prone.self-check-args}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
</parent>
<artifactId>refaster-compiler</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
</parent>
<artifactId>refaster-runner</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
</parent>
<artifactId>refaster-support</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.6.1-SNAPSHOT</version>
<version>0.7.0</version>
</parent>
<artifactId>refaster-test-support</artifactId>

View File

@@ -7,7 +7,7 @@
set -e -u -o pipefail
if [ "${#}" -gt 1 ]; then
echo "Usage: ./$(basename "${0}") [TargetTests]"
echo "Usage: ${0} [TargetTests]"
exit 1
fi

View File

@@ -1,5 +1,5 @@
<img src="/assets/images/picnic-logo@2x.png" alt="Picnic Logo" id="logo"/>
<p>
Copyright &copy; 2017-2022 Picnic Technologies BV
Copyright &copy; 2017-2023 Picnic Technologies BV
</p>

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 63 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 63 KiB