This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 23c46879d2 GH-44013: [Java] Consider warnings as errors for Dataset 
Module (#44014)
23c46879d2 is described below

commit 23c46879d20eabfaf010e34fb03131999a02c30f
Author: Vibhatha Lakmal Abeykoon <[email protected]>
AuthorDate: Tue Sep 10 05:55:20 2024 +0530

    GH-44013: [Java] Consider warnings as errors for Dataset Module (#44014)
    
    ### Rationale for this change
    
    This PR configs the build such that warnings are considered as errors in 
the C module. And corresponding code changes have also been made.
    
    ### What changes are included in this PR?
    
    Adding flags to consider warnings as errors in javac and fixing the 
corresponding errors.
    
    ### Are these changes tested?
    
    Tested by existing test cases.
    
    ### Are there any user-facing changes?
    
    N/A
    * GitHub Issue: #44013
    
    Authored-by: Vibhatha Lakmal Abeykoon <[email protected]>
    Signed-off-by: David Li <[email protected]>
---
 java/dataset/pom.xml                               |  9 +++++++
 .../arrow/dataset/TextBasedWriteSupport.java       | 12 ++++++++--
 .../arrow/dataset/file/TestFileSystemDataset.java  |  7 +++---
 .../arrow/dataset/jni/TestReservationListener.java |  1 +
 .../substrait/TestAceroSubstraitConsumer.java      | 28 ++++++----------------
 5 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/java/dataset/pom.xml b/java/dataset/pom.xml
index a19e934f0d..92b6782551 100644
--- a/java/dataset/pom.xml
+++ b/java/dataset/pom.xml
@@ -202,6 +202,15 @@ under the License.
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration combine.children="append">
+          <compilerArgs>
+            <arg>-Werror</arg>
+          </compilerArgs>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 </project>
diff --git 
a/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java
 
b/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java
index 9e6559824c..e3495bd81c 100644
--- 
a/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java
+++ 
b/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java
@@ -17,10 +17,13 @@
 package org.apache.arrow.dataset;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.Writer;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 import java.util.Random;
 
 public class TextBasedWriteSupport {
@@ -43,7 +46,12 @@ public class TextBasedWriteSupport {
       File outputFolder, String fileExtension, String... values)
       throws URISyntaxException, IOException {
     TextBasedWriteSupport writer = new TextBasedWriteSupport(outputFolder, 
fileExtension);
-    try (FileWriter addValues = new FileWriter(new File(writer.uri), true)) {
+    try (Writer addValues =
+        Files.newBufferedWriter(
+            new File(writer.uri).toPath(),
+            StandardCharsets.UTF_8,
+            StandardOpenOption.CREATE,
+            StandardOpenOption.APPEND)) {
       for (Object value : values) {
         addValues.write(value + "\n");
       }
diff --git 
a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java
 
b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java
index 0b085d25b3..89ce208e8c 100644
--- 
a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java
+++ 
b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java
@@ -29,7 +29,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -407,7 +406,7 @@ public class TestFileSystemDataset extends 
TestNativeDataset {
     try (VectorSchemaRoot root = VectorSchemaRoot.create(sourceSchema, 
rootAllocator());
         FileOutputStream sink = new FileOutputStream(dataFile);
         ArrowFileWriter writer =
-            new ArrowFileWriter(root, /*dictionaryProvider=*/ null, 
sink.getChannel())) {
+            new ArrowFileWriter(root, /* provider= */ null, 
sink.getChannel())) {
       IntVector ints = (IntVector) root.getVector(0);
       ints.setSafe(0, 0);
       ints.setSafe(1, 1024);
@@ -562,7 +561,7 @@ public class TestFileSystemDataset extends 
TestNativeDataset {
       Schema schema, List<GenericRecord> expected, List<ArrowRecordBatch> 
actual) {
     assertEquals(expected.size(), 
actual.stream().mapToInt(ArrowRecordBatch::getLength).sum());
     final int fieldCount = schema.getFields().size();
-    LinkedList<GenericRecord> expectedRemovable = new LinkedList<>(expected);
+    ArrayList<GenericRecord> expectedRemovable = new ArrayList<>(expected);
     try (VectorSchemaRoot vsr = VectorSchemaRoot.create(schema, 
rootAllocator())) {
       VectorLoader loader = new VectorLoader(vsr);
       for (ArrowRecordBatch batch : actual) {
@@ -578,7 +577,7 @@ public class TestFileSystemDataset extends 
TestNativeDataset {
           }
         }
         for (int i = 0; i < batchRowCount; i++) {
-          expectedRemovable.poll();
+          expectedRemovable.remove(0);
         }
       }
       assertTrue(expectedRemovable.isEmpty());
diff --git 
a/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java
 
b/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java
index f366c824d2..9fabc4a257 100644
--- 
a/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java
+++ 
b/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java
@@ -91,6 +91,7 @@ public class TestReservationListener extends TestDataset {
   }
 
   @Test
+  @SuppressWarnings("UnnecessaryAsync")
   public void testErrorThrownFromReservationListener() throws Exception {
     final String errorMessage = "ERROR_MESSAGE";
     ParquetWriteSupport writeSupport =
diff --git 
a/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java
 
b/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java
index 97c185d705..eec6570a63 100644
--- 
a/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java
+++ 
b/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -87,7 +88,8 @@ public class TestAceroSubstraitConsumer extends TestDataset {
                                 TestAceroSubstraitConsumer.class
                                     .getClassLoader()
                                     
.getResource("substrait/local_files_users.json")
-                                    .toURI())))
+                                    .toURI())),
+                        StandardCharsets.UTF_8)
                     .replace("FILENAME_PLACEHOLDER", 
writeSupport.getOutputURI()))) {
       assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema());
       int rowcount = 0;
@@ -134,7 +136,8 @@ public class TestAceroSubstraitConsumer extends TestDataset 
{
                               TestAceroSubstraitConsumer.class
                                   .getClassLoader()
                                   
.getResource("substrait/named_table_users.json")
-                                  .toURI()))),
+                                  .toURI())),
+                      StandardCharsets.UTF_8),
                   mapTableToArrowReader)) {
         assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema());
         assertEquals(arrowReader.getVectorSchemaRoot().getSchema(), schema);
@@ -186,7 +189,8 @@ public class TestAceroSubstraitConsumer extends TestDataset 
{
                                     TestAceroSubstraitConsumer.class
                                         .getClassLoader()
                                         
.getResource("substrait/named_table_users.json")
-                                        .toURI()))),
+                                        .toURI())),
+                            StandardCharsets.UTF_8),
                         mapTableToArrowReader)) {
               assertEquals(schema, 
arrowReader.getVectorSchemaRoot().getSchema());
               int rowcount = 0;
@@ -311,12 +315,6 @@ public class TestAceroSubstraitConsumer extends 
TestDataset {
   @Test
   public void 
testRunExtendedExpressionsFilterWithProjectionsInsteadOfFilterException()
       throws Exception {
-    final Schema schema =
-        new Schema(
-            Arrays.asList(
-                Field.nullable("id", new ArrowType.Int(32, true)),
-                Field.nullable("name", new ArrowType.Utf8())),
-            null);
     // Substrait Extended Expression: Project New Column:
     // Expression ADD: id + 2
     // Expression CONCAT: name + '-' + name
@@ -360,12 +358,6 @@ public class TestAceroSubstraitConsumer extends 
TestDataset {
 
   @Test
   public void testRunExtendedExpressionsFilterWithEmptyFilterException() 
throws Exception {
-    final Schema schema =
-        new Schema(
-            Arrays.asList(
-                Field.nullable("id", new ArrowType.Int(32, true)),
-                Field.nullable("name", new ArrowType.Utf8())),
-            null);
     String base64EncodedSubstraitFilter = "";
     ByteBuffer substraitExpressionFilter = 
getByteBuffer(base64EncodedSubstraitFilter);
     ParquetWriteSupport writeSupport =
@@ -529,12 +521,6 @@ public class TestAceroSubstraitConsumer extends 
TestDataset {
 
   @Test
   public void 
testRunExtendedExpressionsProjectionWithEmptyProjectionException() throws 
Exception {
-    final Schema schema =
-        new Schema(
-            Arrays.asList(
-                Field.nullable("id", new ArrowType.Int(32, true)),
-                Field.nullable("name", new ArrowType.Utf8())),
-            null);
     String base64EncodedSubstraitFilter = "";
     ByteBuffer substraitExpressionProjection = 
getByteBuffer(base64EncodedSubstraitFilter);
     ParquetWriteSupport writeSupport =

Reply via email to