[feature][@CheckReturnValue] Make @CheckReturnValue opt-in rather than opt-out to avoid breaking existing tests.

This commit is contained in:
Tim te Beek authored and Reinier Zwitserloot committed 2026-08-21 02:41:59 +02:00
1 parent cdfb0f551e
commit 14f52226b6
6 files changed
+6 -4

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ import java.lang.annotation.Target;
* Static analysis tools (Error Prone, IntelliJ, SpotBugs) recognize {@code @CheckReturnValue}
* by simple class name, regardless of package, and will warn when the return value is discarded.
* <p>
* If you want to opt out, you can add {@code lombok.addCheckReturnValueAnnotation = false} to
* If you want to opt in, you can add {@code lombok.addCheckReturnValueAnnotation = true} to
* {@code lombok.config}.
*/
@Target({ElementType.METHOD})
+1 -1
View File
@@ -96,7 +96,7 @@ public class ConfigurationKeys {
* If {@code true}, lombok generates {@code @lombok.CheckReturnValue} on generated methods where the return value should not be ignored,
* such as {@code @With} methods and {@code @Builder}'s {@code build()} method.
*/
public static final ConfigurationKey<Boolean> ADD_CHECK_RETURN_VALUE_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addCheckReturnValueAnnotation", "Generate @lombok.CheckReturnValue on generated methods where the return value should not be ignored (default: true).") {};
public static final ConfigurationKey<Boolean> ADD_CHECK_RETURN_VALUE_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addCheckReturnValueAnnotation", "Generate @lombok.CheckReturnValue on generated methods where the return value should not be ignored (default: false).") {};
/**
* lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}.
@@ -2128,7 +2128,7 @@ public class EclipseHandlerUtil {
}
public static Annotation[] addCheckReturnValue(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_CHECK_RETURN_VALUE_ANNOTATIONS))) return originalAnnotationArray;
if (!Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_CHECK_RETURN_VALUE_ANNOTATIONS))) return originalAnnotationArray;
return addAnnotation(source, originalAnnotationArray, LOMBOK_CHECK_RETURN_VALUE);
}
@@ -1555,7 +1555,7 @@ public class JavacHandlerUtil {
}
public static void addCheckReturnValue(JCModifiers mods, JavacNode node, JavacNode source) {
if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_CHECK_RETURN_VALUE_ANNOTATIONS))) return;
if (!Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_CHECK_RETURN_VALUE_ANNOTATIONS))) return;
addAnnotation(mods, node, source, "lombok.CheckReturnValue", null);
}
@@ -1,3 +1,4 @@
//CONF: lombok.addCheckReturnValueAnnotation = true
@lombok.Builder
class CheckReturnValueBuilder {
private final int x;
@@ -1,3 +1,4 @@
//CONF: lombok.addCheckReturnValueAnnotation = true
import lombok.With;
class CheckReturnValueWith {
@With final int x;