-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: main
Are you sure you want to change the base?
Conversation
@@ -16,8 +16,10 @@ | |||
*/ | |||
package org.apache.arrow.flight; | |||
|
|||
import com.google.common.base.Splitter; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's clashing with java.lang.Error
https://docs.oracle.com/javase/8/docs/api/java/lang/Error.html
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
throw new RuntimeException( | ||
"Failed to initialize AddWritableBuffer, falling back to slow path", ex); |
There was a problem hiding this comment.
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
throw new RuntimeException( | ||
"Failed to initialize GetReadableBuffer, falling back to slow path", e); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.5f
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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...
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