From 56ed83bf49d30438679896bd991c0060309d81c4 Mon Sep 17 00:00:00 2001 From: Max Sumrall Date: Mon, 13 Feb 2023 09:56:28 +0100 Subject: [PATCH] XXX-XXX Prefer jOOQs fetch().stream() over directly .stream()'ing --- error-prone-contrib/pom.xml | 4 +++ .../errorprone/refasterrules/JooqRules.java | 29 +++++++++++++++++++ .../refasterrules/RefasterRulesTest.java | 1 + .../refasterrules/JooqRulesTestInput.java | 11 +++++++ .../refasterrules/JooqRulesTestOutput.java | 11 +++++++ pom.xml | 7 +++++ 6 files changed, 63 insertions(+) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JooqRules.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestOutput.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index b16612d0e5..af6064c976 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -146,6 +146,10 @@ value-annotations test + + org.jooq + jooq + org.jspecify jspecify diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JooqRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JooqRules.java new file mode 100644 index 0000000000..72205bcf4b --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JooqRules.java @@ -0,0 +1,29 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import java.util.stream.Stream; +import org.jooq.Record; +import org.jooq.ResultQuery; +import tech.picnic.errorprone.refaster.annotation.Description; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; + +@OnlineDocumentation +final class JooqRules { + private JooqRules() {} + + /** Prefer eagerly fetching data over (lazy) streaming to avoid potentially leaking resources. */ + @Description( + "Prefer eagerly fetching data over (lazy) streaming to avoid potentially leaking resources.") + static final class ResultQueryFetchStream { + @BeforeTemplate + Stream before(ResultQuery resultQuery) { + return resultQuery.stream(); + } + + @AfterTemplate + Stream after(ResultQuery resultQuery) { + return resultQuery.fetch().stream(); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index c60bb8b286..50177d8d48 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -49,6 +49,7 @@ final class RefasterRulesTest { ImmutableSortedMultisetRules.class, ImmutableSortedSetRules.class, IntStreamRules.class, + JooqRules.class, JUnitRules.class, JUnitToAssertJRules.class, LongStreamRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestInput.java new file mode 100644 index 0000000000..d0a213a13f --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestInput.java @@ -0,0 +1,11 @@ +package tech.picnic.errorprone.refasterrules; + +import java.util.stream.Stream; +import org.jooq.impl.DSL; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class JooqRulesTest implements RefasterRuleCollectionTestCase { + Stream testResultQueryFetchStream() { + return DSL.select().stream(); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestOutput.java new file mode 100644 index 0000000000..c5b046b4ce --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JooqRulesTestOutput.java @@ -0,0 +1,11 @@ +package tech.picnic.errorprone.refasterrules; + +import java.util.stream.Stream; +import org.jooq.impl.DSL; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class JooqRulesTest implements RefasterRuleCollectionTestCase { + Stream testResultQueryFetchStream() { + return DSL.select().fetch().stream(); + } +} diff --git a/pom.xml b/pom.xml index 96605afd9e..1656542a52 100644 --- a/pom.xml +++ b/pom.xml @@ -368,6 +368,11 @@ value-annotations 2.9.3 + + org.jooq + jooq + 3.16.14 + org.jspecify jspecify @@ -1178,6 +1183,8 @@ | BSD 3-clause | BSD License 3 | Eclipse Distribution License (New BSD License) + | Eclipse Distribution License - v 1.0 + | EDL 1.0 | New BSD License