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

GH-44055: [Java] Finalize ErrorProne Warnings to be considered as Errors #44056

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
13 changes: 0 additions & 13 deletions java/adapter/avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,4 @@ under the License.
</dependency>
</dependencies>

<build>
<plugins>
<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>
16 changes: 7 additions & 9 deletions java/adapter/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ under the License.
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down Expand Up @@ -116,15 +123,6 @@ under the License.
<argLine>--add-reads=org.apache.arrow.adapter.jdbc=com.fasterxml.jackson.dataformat.yaml --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED -Duser.timezone=UTC</argLine>
</configuration>
</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>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.arrow.vector.util.JsonStringHashMap;
import org.apache.arrow.vector.util.ObjectMapperFactory;
import org.apache.arrow.vector.util.Text;
import org.apache.commons.lang3.StringUtils;

/**
* This is a Helper class which has functionalities to read and assert the values from the given
Expand Down Expand Up @@ -447,24 +448,22 @@ public static byte[][] getBinaryValues(String[] values, String dataType) {
return valueArr;
}

@SuppressWarnings("StringSplitter")
public static String[] getValues(String[] values, String dataType) {
String value = "";
for (String val : values) {
if (val.startsWith(dataType)) {
value = val.split("=")[1];
value = StringUtils.split(val, "=")[1];
break;
}
}
return value.split(",");
return StringUtils.split(value, ",");
}

public static Integer[][] getListValues(String[] values, String dataType) {
String[] dataArr = getValues(values, dataType);
return getListValues(dataArr);
}

@SuppressWarnings("StringSplitter")
public static Integer[][] getListValues(String[] dataArr) {
Integer[][] valueArr = new Integer[dataArr.length][];
int i = 0;
Expand All @@ -474,7 +473,7 @@ public static Integer[][] getListValues(String[] dataArr) {
} else if ("()".equals(data.trim())) {
valueArr[i++] = new Integer[0];
} else {
String[] row = data.replace("(", "").replace(")", "").split(";");
String[] row = StringUtils.split(data.replace("(", "").replace(")", ""), ";");
Integer[] arr = new Integer[row.length];
for (int j = 0; j < arr.length; j++) {
arr[j] = "null".equals(row[j]) ? null : Integer.parseInt(row[j]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getLongValues;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
Expand Down Expand Up @@ -146,10 +146,10 @@ public void testVectorSchemaRootReuse(Table table, boolean reuseVectorSchemaRoot

if (reuseVectorSchemaRoot) {
// when reuse is enabled, different iterations are based on the same vector schema root.
assertTrue(prev == cur);
assertSame(prev, cur);
} else {
// when reuse is enabled, a new vector schema root is created in each iteration.
assertFalse(prev == cur);
assertNotEquals(prev, cur);
if (batchCount < 3) {
cur.close();
}
Expand Down
9 changes: 0 additions & 9 deletions java/adapter/orc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,6 @@ 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>
11 changes: 0 additions & 11 deletions java/c/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,5 @@ under the License.
</includes>
</resource>
</resources>
<plugins>
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.arrow.c;

import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.DATA_VECTOR_NAME;
import static org.apache.arrow.vector.testing.ValueVectorDataPopulator.setVector;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -965,7 +966,9 @@ public void testImportReleasedArray() {
try (ArrowSchema arrowSchema = ArrowSchema.wrap(consumerArrowSchema.memoryAddress());
ArrowArray arrowArray = ArrowArray.wrap(consumerArrowArray.memoryAddress())) {
// Producer exports vector into the C Data Interface structures
try (final NullVector vector = new NullVector()) {
try (final NullVector vector =
new NullVector(
new Field(DATA_VECTOR_NAME, FieldType.nullable(new ArrowType.Null()), null))) {
Data.exportVector(allocator, vector, null, arrowArray, arrowSchema);
}
}
Expand Down
9 changes: 0 additions & 9 deletions java/dataset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ 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>
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static Status fromProtocol(Flight.CloseSessionResult.Status proto) {
return values()[proto.getNumber()];
}

@SuppressWarnings("EnumOrdinal")
public Flight.CloseSessionResult.Status toProtocol() {
return Flight.CloseSessionResult.Status.values()[ordinal()];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static Schema generateSchemaMessages(
count);
final VectorUnloader unloader = new VectorUnloader(dictRoot);
try (final ArrowDictionaryBatch dictionaryBatch =
new ArrowDictionaryBatch(id, unloader.getRecordBatch());
new ArrowDictionaryBatch(id, unloader.getRecordBatch(), false);
final ArrowMessage message = new ArrowMessage(dictionaryBatch, option)) {
messageCallback.accept(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public CallStatus status() {

@Override
public String toString() {
return getMessage();
}

@Override
public String getMessage() {
String s = getClass().getName();
return String.format("%s: %s: %s", s, status.code(), status.description());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,31 @@
*/
public class NoOpSessionOptionValueVisitor<T> implements SessionOptionValueVisitor<T> {
/** A callback to handle SessionOptionValue containing a String. */
@Override
public T visit(String value) {
return null;
}

/** A callback to handle SessionOptionValue containing a boolean. */
@Override
public T visit(boolean value) {
return null;
}

/** A callback to handle SessionOptionValue containing a long. */
@Override
public T visit(long value) {
return null;
}

/** A callback to handle SessionOptionValue containing a double. */
@Override
public T visit(double value) {
return null;
}

/** A callback to handle SessionOptionValue containing an array of String. */
@Override
public T visit(String[] value) {
return null;
}
Expand All @@ -55,6 +60,7 @@ public T visit(String[] value) {
* <p>By convention, an attempt to set a valueless SessionOptionValue should attempt to unset or
* clear the named option value on the server.
*/
@Override
public T visit(Void value) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private void closeSession(String id) {
}

@Override
@SuppressWarnings("StringSplitter")
public ServerSessionMiddleware onCallStarted(
CallInfo callInfo, CallHeaders incomingHeaders, RequestContext context) {
String sessionId = null;
Expand All @@ -90,7 +91,7 @@ public ServerSessionMiddleware onCallStarted(
break;
}

if (sessionCookieName.equals(cookiePair[0]) && cookiePair[1].length() > 0) {
if (sessionCookieName.equals(cookiePair[0]) && !cookiePair[1].isEmpty()) {
sessionId = cookiePair[1];
break findIdCookie;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public boolean isEmpty() {
return false;
}

private class SessionOptionValueToProtocolVisitor implements SessionOptionValueVisitor<Void> {
private static class SessionOptionValueToProtocolVisitor
implements SessionOptionValueVisitor<Void> {
final Flight.SessionOptionValue.Builder b;

SessionOptionValueToProtocolVisitor(Flight.SessionOptionValue.Builder b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueString)) {
return false;
}
SessionOptionValueString that = (SessionOptionValueString) o;
Expand Down Expand Up @@ -124,7 +124,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueBoolean)) {
return false;
}
SessionOptionValueBoolean that = (SessionOptionValueBoolean) o;
Expand Down Expand Up @@ -159,7 +159,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueLong)) {
return false;
}
SessionOptionValueLong that = (SessionOptionValueLong) o;
Expand Down Expand Up @@ -194,7 +194,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueDouble)) {
return false;
}
SessionOptionValueDouble that = (SessionOptionValueDouble) o;
Expand Down Expand Up @@ -229,7 +229,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueStringList)) {
return false;
}
SessionOptionValueStringList that = (SessionOptionValueStringList) o;
Expand Down Expand Up @@ -266,7 +266,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof SessionOptionValueEmpty)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ static ErrorValue fromProtocol(Flight.SetSessionOptionsResult.ErrorValue s) {
return values()[s.getNumber()];
}

@SuppressWarnings("EnumOrdinal")
Copy link
Member

Choose a reason for hiding this comment

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

IMO, the right way to do this would be to add a constructor and store the Protobuf enum value in the enum instance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, that is the ideal way. Let me track down and change the similar other instances.

Flight.SetSessionOptionsResult.ErrorValue toProtocol() {
return Flight.SetSessionOptionsResult.ErrorValue.values()[ordinal()];
}
}

/** Per-option extensible error response container. */
@SuppressWarnings("JavaLangClash")
Copy link
Member

Choose a reason for hiding this comment

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

What was the problem here?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

+1 for renaming it, if it's not an external API change in some way

Copy link
Member

Choose a reason for hiding this comment

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

This is public, it will be a breaking change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, the issue is as @danepitkin mentioned. Shall we leave the warning suppressed?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's leave the suppression in place.

public static class Error {
public ErrorValue value;

Expand All @@ -74,7 +76,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof Error)) {
return false;
}
Error that = (Error) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public class AddWritableBuffer {
tmpBufChainOut = tmpBufChainOut2;

} catch (Exception ex) {
new RuntimeException("Failed to initialize AddWritableBuffer, falling back to slow path", ex)
.printStackTrace();
throw new RuntimeException(
"Failed to initialize AddWritableBuffer, falling back to slow path", ex);
Comment on lines +73 to +74
Copy link
Member

Choose a reason for hiding this comment

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

I think this intentionally did not throw, as evidenced by the "falling back" message

}

bufConstruct = tmpConstruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class GetReadableBuffer {
tmpField = f;
tmpClazz = clazz;
} catch (Exception e) {
new RuntimeException("Failed to initialize GetReadableBuffer, falling back to slow path", e)
.printStackTrace();
throw new RuntimeException(
"Failed to initialize GetReadableBuffer, falling back to slow path", e);
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}
READABLE_BUFFER = tmpField;
BUFFER_INPUT_STREAM = tmpClazz;
Expand Down
Loading
Loading