From 09ed5e5c4ed9e7fd1619bf3bf3a5c88be4540a40 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Tue, 10 Sep 2024 05:56:18 +0530 Subject: [PATCH] GH-44011: [Java] Consider warnings as errors for C Module (#44012) ### 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: #44011 Authored-by: Vibhatha Lakmal Abeykoon Signed-off-by: David Li --- java/c/pom.xml | 11 +++++++++++ .../main/java/org/apache/arrow/c/ArrayExporter.java | 2 +- .../org/apache/arrow/c/BufferImportTypeVisitor.java | 2 +- .../test/java/org/apache/arrow/c/DictionaryTest.java | 8 ++++---- .../test/java/org/apache/arrow/c/RoundtripTest.java | 8 -------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/java/c/pom.xml b/java/c/pom.xml index 52962354047b1..fe57bd2ea0ec5 100644 --- a/java/c/pom.xml +++ b/java/c/pom.xml @@ -91,5 +91,16 @@ under the License. + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Werror + + + + diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java index 820a1522749c6..0c6b5de4486bc 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java @@ -90,7 +90,7 @@ void export(ArrowArray array, FieldVector vector, DictionaryProvider dictionaryP data.buffers = new ArrayList<>(vector.getExportedCDataBufferCount()); data.buffers_ptrs = - allocator.buffer((long) (vector.getExportedCDataBufferCount()) * Long.BYTES); + allocator.buffer((long) vector.getExportedCDataBufferCount() * Long.BYTES); vector.exportCDataBuffers(data.buffers, data.buffers_ptrs, NULL); if (dictionaryEncoding != null) { diff --git a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java index 93fef6d7ca801..e47d27bf091ee 100644 --- a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java +++ b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java @@ -232,7 +232,7 @@ public List visit(ArrowType.Utf8 type) { private List visitVariableWidthView(ArrowType type) { final int viewBufferIndex = 1; final int variadicSizeBufferIndex = this.buffers.length - 1; - final long numOfVariadicBuffers = this.buffers.length - 3; + final long numOfVariadicBuffers = this.buffers.length - 3L; final long variadicSizeBufferCapacity = numOfVariadicBuffers * Long.BYTES; List buffers = new ArrayList<>(); diff --git a/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java b/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java index ce0e82586b766..8cd4913f22dd2 100644 --- a/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java @@ -247,8 +247,8 @@ private void createStructVector(StructVector vector) { // Write the values to child 1 child1.allocateNew(); - child1.set(0, "01234567890".getBytes()); - child1.set(1, "012345678901234567".getBytes()); + child1.set(0, "01234567890".getBytes(StandardCharsets.UTF_8)); + child1.set(1, "012345678901234567".getBytes(StandardCharsets.UTF_8)); vector.setIndexDefined(0); // Write the values to child 2 @@ -269,8 +269,8 @@ private void createStructVectorInline(StructVector vector) { // Write the values to child 1 child1.allocateNew(); - child1.set(0, "012345678".getBytes()); - child1.set(1, "01234".getBytes()); + child1.set(0, "012345678".getBytes(StandardCharsets.UTF_8)); + child1.set(1, "01234".getBytes(StandardCharsets.UTF_8)); vector.setIndexDefined(0); // Write the values to child 2 diff --git a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java index 18b2e94adde47..d8286465e475f 100644 --- a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java @@ -528,14 +528,6 @@ public void testVarBinaryVector() { } } - private String generateString(String str, int repetition) { - StringBuilder aRepeated = new StringBuilder(); - for (int i = 0; i < repetition; i++) { - aRepeated.append(str); - } - return aRepeated.toString(); - } - @Test public void testViewVector() { // ViewVarCharVector with short strings