[
https://issues.apache.org/jira/browse/BEAM-4349?focusedWorklogId=104768&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-104768
]
ASF GitHub Bot logged work on BEAM-4349:
----------------------------------------
Author: ASF GitHub Bot
Created on: 22/May/18 19:46
Start Date: 22/May/18 19:46
Worklog Time Spent: 10m
Work Description: iemejia closed pull request #5450: [BEAM-4349] Enforce
ErrorProne analysis in mongodb IO
URL: https://github.com/apache/beam/pull/5450
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/java/io/mongodb/build.gradle
b/sdks/java/io/mongodb/build.gradle
index dc5b275045d..24da98ab86d 100644
--- a/sdks/java/io/mongodb/build.gradle
+++ b/sdks/java/io/mongodb/build.gradle
@@ -17,7 +17,7 @@
*/
apply from: project(":").file("build_rules.gradle")
-applyJavaNature()
+applyJavaNature(failOnWarning: true)
provideIntegrationTestingDependencies()
enableJavaPerformanceTesting()
@@ -26,6 +26,7 @@ ext.summary = "IO to read and write on MongoDB."
dependencies {
compile library.java.guava
+ compileOnly library.java.findbugs_annotations
shadow project(path: ":beam-sdks-java-core", configuration: "shadow")
shadow library.java.slf4j_api
shadow library.java.findbugs_jsr305
@@ -39,4 +40,5 @@ dependencies {
testCompile project(path: ":beam-sdks-java-io-common", configuration:
"shadowTest")
testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.50.1"
testCompile "de.flapdoodle.embed:de.flapdoodle.embed.process:1.50.1"
+ testCompileOnly library.java.findbugs_annotations
}
diff --git
a/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbGridFSIO.java
b/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbGridFSIO.java
index 3f08d9dac18..04503ad2b04 100644
---
a/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbGridFSIO.java
+++
b/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbGridFSIO.java
@@ -153,7 +153,8 @@
(input, callback) -> {
final Instant time = new Instant(input.getUploadDate().getTime());
try (BufferedReader reader =
- new BufferedReader(new InputStreamReader(input.getInputStream())))
{
+ new BufferedReader(
+ new InputStreamReader(input.getInputStream(),
StandardCharsets.UTF_8))) {
for (String line = reader.readLine(); line != null; line =
reader.readLine()) {
callback.output(line, time);
}
@@ -496,6 +497,7 @@ public ObjectId getCurrent() throws NoSuchElementException {
return current;
}
+ @Override
public Instant getCurrentTimestamp() throws NoSuchElementException {
if (current == null) {
throw new NoSuchElementException();
diff --git
a/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbIO.java
b/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbIO.java
index 5e35c7933b2..87d0dcad1a5 100644
---
a/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbIO.java
+++
b/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbIO.java
@@ -228,7 +228,7 @@ public Read withFilter(String filter) {
* Sets the user defined number of splits.
*/
public Read withNumSplits(int numSplits) {
- checkArgument(numSplits >= 0, "invalid num_splits: must be >= 0, but was
%d", numSplits);
+ checkArgument(numSplits >= 0, "invalid num_splits: must be >= 0, but was
%s", numSplits);
return builder().setNumSplits(numSplits).build();
}
@@ -597,7 +597,7 @@ public Write withCollection(String collection) {
* Define the size of the batch to group write operations.
*/
public Write withBatchSize(long batchSize) {
- checkArgument(batchSize >= 0, "Batch size must be >= 0, but was %d",
batchSize);
+ checkArgument(batchSize >= 0, "Batch size must be >= 0, but was %s",
batchSize);
return builder().setBatchSize(batchSize).build();
}
diff --git
a/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDBGridFSIOTest.java
b/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDBGridFSIOTest.java
index 2724bf988ff..b008e4b700f 100644
---
a/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDBGridFSIOTest.java
+++
b/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDBGridFSIOTest.java
@@ -131,8 +131,10 @@ public static void setup() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int x = 0; x < 100; x++) {
- out.write(("Einstein\nDarwin\nCopernicus\nPasteur\n"
- +
"Curie\nFaraday\nNewton\nBohr\nGalilei\nMaxwell\n").getBytes());
+ out.write(
+ ("Einstein\nDarwin\nCopernicus\nPasteur\n"
+ + "Curie\nFaraday\nNewton\nBohr\nGalilei\nMaxwell\n")
+ .getBytes(StandardCharsets.UTF_8));
}
for (int x = 0; x < 5; x++) {
gridfs.createFile(new ByteArrayInputStream(out.toByteArray()), "file" +
x).save();
@@ -146,7 +148,7 @@ public static void setup() throws Exception {
for (int x = 0; x < 10; x++) {
GridFSInputFile file = gridfs.createFile("file_" + x);
OutputStream outf = file.getOutputStream();
- OutputStreamWriter writer = new OutputStreamWriter(outf);
+ OutputStreamWriter writer = new OutputStreamWriter(outf,
StandardCharsets.UTF_8);
for (int y = 0; y < 5000; y++) {
long time = now - random.nextInt(3600000);
String name = scientists[y % scientists.length];
@@ -210,7 +212,9 @@ public void testReadWithParser() throws Exception {
.<KV<String, Integer>>withParser(
(input, callback) -> {
try (final BufferedReader reader =
- new BufferedReader(new
InputStreamReader(input.getInputStream()))) {
+ new BufferedReader(
+ new InputStreamReader(
+ input.getInputStream(),
StandardCharsets.UTF_8))) {
String line = reader.readLine();
while (line != null) {
try (Scanner scanner = new Scanner(line.trim())) {
diff --git
a/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDbIOTest.java
b/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDbIOTest.java
index 07b4821b34b..ecccfeb73dd 100644
---
a/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDbIOTest.java
+++
b/sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDbIOTest.java
@@ -173,6 +173,7 @@ public void testFullRead() throws Exception {
"Map Scientist",
MapElements.via(
new SimpleFunction<Document, KV<String, Void>>() {
+ @Override
public KV<String, Void> apply(Document input) {
return KV.of(input.getString("scientist"), null);
}
@@ -210,6 +211,7 @@ public void testReadWithCustomConnectionOptions() throws
Exception {
"Map Scientist",
MapElements.via(
new SimpleFunction<Document, KV<String, Void>>() {
+ @Override
public KV<String, Void> apply(Document input) {
return KV.of(input.getString("scientist"), null);
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 104768)
Time Spent: 20m (was: 10m)
> Enforce ErrorProne analysis in the mongodb IO project
> -----------------------------------------------------
>
> Key: BEAM-4349
> URL: https://issues.apache.org/jira/browse/BEAM-4349
> Project: Beam
> Issue Type: Improvement
> Components: io-java-mongodb
> Reporter: Scott Wegner
> Assignee: Tim Robertson
> Priority: Minor
> Labels: errorprone, starter
> Fix For: 2.5.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Java ErrorProne static analysis was [recently
> enabled|https://github.com/apache/beam/pull/5161] in the Gradle build
> process, but only as warnings. ErrorProne errors are generally useful and
> easy to fix. Some work was done to [make sdks-java-core
> ErrorProne-clean|https://github.com/apache/beam/pull/5319] and add
> enforcement. This task is clean ErrorProne warnings and add enforcement in
> {{beam-sdks-java-io-mongodb}}. Additional context discussed on the [dev
> list|https://lists.apache.org/thread.html/95aae2785c3cd728c2d3378cbdff2a7ba19caffcd4faa2049d2e2f46@%3Cdev.beam.apache.org%3E].
> Fixing this issue will involve:
> # Follow instructions in the [Contribution
> Guide|https://beam.apache.org/contribute/] to set up a {{beam}} development
> environment.
> # Run the following command to compile and run ErrorProne analysis on the
> project: {{./gradlew :beam-sdks-java-io-mongodb:assemble}}
> # Fix each ErrorProne warning from the {{sdks/java/io/mongodb}} project.
> # In {{sdks/java/io/mongodb/build.gradle}}, add {{failOnWarning: true}} to
> the call the {{applyJavaNature()}}
> ([example|https://github.com/apache/beam/pull/5319/files#diff-9390c20635aed5f42f83b97506a87333R20]).
> This starter issue is sponsored by [~swegner]. Feel free to [reach
> out|https://beam.apache.org/community/contact-us/] with questions or code
> review:
> * JIRA: [~swegner]
> * GitHub: [@swegner|https://github.com/swegner]
> * Slack: [@Scott Wegner|https://s.apache.org/beam-slack-channel]
> * Email: swegner at google dot com
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)