From 451643cad174252abf9411d2860e9d67786fcc04 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 18 Aug 2022 14:20:18 +0200 Subject: [PATCH] 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 f35bd720a37..1e7460ce19f 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);