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

Conversation

vibhatha
Copy link
Collaborator

@vibhatha vibhatha commented Sep 11, 2024

Rationale for this change

A series of PRs have been created to mark warnings as errors in a module-based approach. As this step has been completed, moving the config back to the parent pom would be the best to keep things clean and easy to maintain.

What changes are included in this PR?

Removing the pom changes in each module and updating the parent pom with the required configurations.

Are these changes tested?

Tested from existing test cases.

Are there any user-facing changes?

N/A

@vibhatha vibhatha changed the title [Java] Finalize ErrorProne Warnings to be considered as Errors #44055 GH-44055: [Java] Finalize ErrorProne Warnings to be considered as Errors Sep 11, 2024
@github-actions github-actions bot added the awaiting review Awaiting review label Sep 11, 2024
@vibhatha vibhatha marked this pull request as ready for review September 13, 2024 08:29
@@ -16,8 +16,10 @@
*/
package org.apache.arrow.flight;

import com.google.common.base.Splitter;
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we wouldn't use Guava? I suppose as long as this interface seems stable...

Is there an apache-commons equivalent we can use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will take a look, this was actually suggested by the ErrorProne library, it wasn't my first choice.

@@ -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.

Comment on lines +73 to +74
throw new RuntimeException(
"Failed to initialize AddWritableBuffer, falling back to slow path", ex);
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

Comment on lines +50 to +51
throw new RuntimeException(
"Failed to initialize GetReadableBuffer, falling back to slow path", e);
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

@@ -277,7 +278,8 @@ Optional<Map<Object, Object>> getUrlsArgs(String url) throws SQLException {

static Properties lowerCasePropertyKeys(final Properties properties) {
final Properties resultProperty = new Properties();
properties.forEach((k, v) -> resultProperty.put(k.toString().toLowerCase(), v));
properties.forEach(
(k, v) -> resultProperty.put(k.toString().toLowerCase(Locale.getDefault()), v));
Copy link
Member

Choose a reason for hiding this comment

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

let's use Locale.ROOT rather than the system locale

@@ -71,6 +71,7 @@ public String getString() {
}

@Override
@SuppressWarnings("BigDecimalEquals")
Copy link
Member

Choose a reason for hiding this comment

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

@@ -241,7 +243,7 @@ public Object get(final Properties properties) {
Preconditions.checkNotNull(properties, "Properties cannot be null.");
Object value = properties.get(camelName);
if (value == null) {
value = properties.get(camelName.toLowerCase());
value = properties.get(camelName.toLowerCase(Locale.getDefault()));
Copy link
Member

Choose a reason for hiding this comment

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

Locale.ROOT

@@ -220,7 +220,10 @@ public void testShouldFailToPrepareStatementForBadStatement() {
*/
assertThat(
e.getMessage(),
is(format("Error while executing SQL \"%s\": Query not found", badQuery)));
is(
Copy link
Member

Choose a reason for hiding this comment

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

Would prefer contains

@@ -1240,7 +1240,7 @@ public static class PreparedStatement implements AutoCloseable {
* used in the {@code PreparedStatement} setters.
*/
public void setParameters(final VectorSchemaRoot parameterBindingRoot) {
if (parameterBindingRoot == this.parameterBindingRoot) {
if (parameterBindingRoot.equals(this.parameterBindingRoot)) {
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 was intentionally an identity check

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. I will leave it as it is, and add the suppressing.

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend adding a comment alongside warning suppressions for future readers. It's not always obvious if a Warning suppression is the result of a temporary bug, laziness from the developers (not you, just in general :P), or is truly an unhelpful warning.

Copy link
Member

Choose a reason for hiding this comment

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

For example, we would never want to un-suppress this warning because we want to compare object references, but for the Flatbuffers module name warning in an older PR, we want to eventually remove it once fixed.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Sep 13, 2024
Copy link
Member

@danepitkin danepitkin left a comment

Choose a reason for hiding this comment

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

Heroic effort 👏 Nice job @vibhatha.

@@ -1240,7 +1240,7 @@ public static class PreparedStatement implements AutoCloseable {
* used in the {@code PreparedStatement} setters.
*/
public void setParameters(final VectorSchemaRoot parameterBindingRoot) {
if (parameterBindingRoot == this.parameterBindingRoot) {
if (parameterBindingRoot.equals(this.parameterBindingRoot)) {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend adding a comment alongside warning suppressions for future readers. It's not always obvious if a Warning suppression is the result of a temporary bug, laziness from the developers (not you, just in general :P), or is truly an unhelpful warning.

@@ -1240,7 +1240,7 @@ public static class PreparedStatement implements AutoCloseable {
* used in the {@code PreparedStatement} setters.
*/
public void setParameters(final VectorSchemaRoot parameterBindingRoot) {
if (parameterBindingRoot == this.parameterBindingRoot) {
if (parameterBindingRoot.equals(this.parameterBindingRoot)) {
Copy link
Member

Choose a reason for hiding this comment

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

For example, we would never want to un-suppress this warning because we want to compare object references, but for the Flatbuffers module name warning in an older PR, we want to eventually remove it once fixed.

@@ -42,7 +42,10 @@ public class Filter {

private final JniWrapper wrapper;
private final long moduleId;

@SuppressWarnings("UnusedVariable")
Copy link
Member

Choose a reason for hiding this comment

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

This actually looks unused. It's private, and not used after object instantiation. Should we remove it?

@@ -45,7 +45,10 @@ public class Projector {

private JniWrapper wrapper;
private final long moduleId;

@SuppressWarnings("UnusedVariable")
Copy link
Member

Choose a reason for hiding this comment

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

We can probably delete this, too.

@@ -154,13 +154,13 @@ public static class ConsumeState {

private JdbcConsumer<BitVector> bitConsumer;

private JdbcToArrowConfig config;
// private JdbcToArrowConfig config;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be deleted?

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs combine.children="override">
Copy link
Member

Choose a reason for hiding this comment

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

Are we trying to override and disable warnings-as-errors for this module? If so, it should be combine.self="override".

@@ -283,6 +287,7 @@ public Void visit(NullVector vector, Void value) {
}

@Override
@SuppressWarnings("VoidUsed")
Copy link
Member

Choose a reason for hiding this comment

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

You could use vector.getUnderlyingVector().accept(this, null); and get rid of the suppressed warning.

@@ -202,6 +202,7 @@ public Void visit(NullVector vector, Void value) {
}

@Override
@SuppressWarnings("VoidUsed")
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. vector.getUnderlyingVector().accept(this, null);

@@ -314,6 +316,7 @@ public Void visit(NullVector vector, Void value) {
}

@Override
@SuppressWarnings("VoidUsed")
Copy link
Member

Choose a reason for hiding this comment

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

and here

@@ -176,6 +176,7 @@ public void testShouldGetStringMethodFromDecimalVector(Supplier<ValueVector> vec

@ParameterizedTest
@MethodSource("data")
@SuppressWarnings("BigDecimalEquals")
Copy link
Member

Choose a reason for hiding this comment

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

use compareTo

@@ -73,7 +75,8 @@ public boolean equals(Object signature) {

@Override
public int hashCode() {
return Objects.hashCode(this.name.toLowerCase(), this.returnType, this.paramTypes);
return Objects.hashCode(
this.name.toLowerCase(Locale.getDefault()), this.returnType, this.paramTypes);
Copy link
Member

Choose a reason for hiding this comment

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

Locale.ROOT

}

@Override
public String getMessage() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is the trivial override needed?

node = n.toProtobuf();
assertEquals(10, node.getIntNode().getValue());

n = TreeBuilder.makeLiteral(new Long(50));
n = TreeBuilder.makeLiteral(Long.valueOf(50));
Copy link
Member

Choose a reason for hiding this comment

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

50L doesn't work?

node = n.toProtobuf();
assertEquals(50, node.getLongNode().getValue());

Float f = new Float(2.5);
Float f = (float) 2.5;
Copy link
Member

Choose a reason for hiding this comment

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

2.5f

Copy link
Member

Choose a reason for hiding this comment

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

And does it need to be boxed?

@@ -385,7 +385,7 @@ public static void concatBits(
}

// copy the first bit set
if (input1 != output) {
if (!input1.equals(output)) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I wonder if this was intentional or not.

@@ -138,12 +144,12 @@ public Boolean visit(LargeListViewVector left, Void value) {

private boolean compareField(Field leftField, Field rightField) {

if (leftField == rightField) {
if (leftField.equals(rightField)) {
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 was intentional: it's a cheap "is this actually the same object" check, before doing the rest of the checks below

@@ -62,10 +62,16 @@ public TypeEqualsVisitor(ValueVector right, boolean checkName, boolean checkMeta
}

/** Check type equals without passing IN param in VectorVisitor. */
@SuppressWarnings("NonOverridingEquals")
public boolean equals(ValueVector left) {
Copy link
Member

Choose a reason for hiding this comment

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

...this shoulda been named something different but it's way too late now

@@ -372,6 +376,16 @@ public boolean equals(VectorSchemaRoot other) {
return true;
}

@Override
public int hashCode() {
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 a mutable object, I'm not sure we want it to have a hashCode...

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants