From 2fc399fc8410cf9c807299961de19a1aba12cb4b Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 18 Aug 2022 14:20:18 +0200 Subject: [PATCH 1/2] Update `StreamMapToOptionalGet` Javadoc --- .../refastertemplates/OptionalTemplates.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java index f35bd720a3..1e7460ce19 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java @@ -239,9 +239,16 @@ Stream after(Stream> stream) { } } - /** Within a stream's map operation unconditional {@link Optional#get()} calls can be avoided. */ - // XXX: An alternative approach is to `.flatMap(Optional::stream)`. That may be a bit longer, but - // yield nicer code. Think about it. + /** + * Within a stream's map operation unconditional {@link Optional#orElseThrow()} calls can be + * avoided. + * + *

Warning: this rewrite rule is not completely behavior preserving. The + * original code throws an exception if no value is present, while the replacement will silently + * continue. + */ + // XXX: An alternative approach is to use `.flatMap(Optional::stream)`. That may be a bit longer, + // but yields nicer code. Think about it. abstract static class StreamMapToOptionalGet { @Placeholder abstract Optional toOptionalFunction(@MayOptionallyUse T element); From 493db87702494305486c56be0a91cf0d57baf18d Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 19 Aug 2022 08:52:29 +0200 Subject: [PATCH 2/2] Tweak --- .../errorprone/refastertemplates/OptionalTemplates.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java index 1e7460ce19..ea645ecfa6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java @@ -244,8 +244,8 @@ Stream after(Stream> stream) { * avoided. * *

Warning: this rewrite rule is not completely behavior preserving. The - * original code throws an exception if no value is present, while the replacement will silently - * continue. + * original code throws an exception if the mapping operation does not produce a value, while the + * replacement does not. */ // XXX: An alternative approach is to use `.flatMap(Optional::stream)`. That may be a bit longer, // but yields nicer code. Think about it.