Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ResultQueryFetchStream Refaster rule #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
<artifactId>value-annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.")
Copy link
Contributor

@ferdinand-swoboda ferdinand-swoboda Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to link to the Jooq blogpost here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it would be useful, it might not be wise as the blogpost might move URLs one day, and then the code is not correct. I think that would not be prudent in a library such as this. Perhaps linking to it in this PR is enough for curious folks to find one day if they go looking for the motivations for this rule.

static final class ResultQueryFetchStream {
@BeforeTemplate
Stream<?> before(ResultQuery<? extends Record> resultQuery) {
return resultQuery.stream();
}

@AfterTemplate
Stream<?> after(ResultQuery<? extends Record> resultQuery) {
return resultQuery.fetch().stream();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class RefasterRulesTest {
ImmutableSortedMultisetRules.class,
ImmutableSortedSetRules.class,
IntStreamRules.class,
JooqRules.class,
JUnitRules.class,
JUnitToAssertJRules.class,
LongStreamRules.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@
<artifactId>value-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.16.14</version>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the latest version of jOOQ supporting Java 11. From 3.17.x, it is not supported.

</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
Expand Down Expand Up @@ -1178,6 +1183,8 @@
| BSD 3-clause
| BSD License 3
| Eclipse Distribution License (New BSD License)
| Eclipse Distribution License - v 1.0
Copy link
Member Author

@maxsumrall maxsumrall Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source:

[WARNING] License: 'Eclipse Distribution License - v 1.0' used by 1 dependencies:
 -Jakarta XML Binding API (jakarta.xml.bind:jakarta.xml.bind-api:3.0.0 - https://github.com/eclipse-ee4j/jaxb-api/jakarta.xml.bind-api)

| EDL 1.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source:

[WARNING] License: 'EDL 1.0' used by 1 dependencies:
 -Jakarta Activation (com.sun.activation:jakarta.activation:2.0.0 - https://github.com/eclipse-ee4j/jaf/jakarta.activation)

| New BSD License
</licenseMerge>
<licenseMerge>
Expand Down