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

Fix compiler warnings in :server - part 2 #75792

Merged

Conversation

pugnascotia
Copy link
Contributor

Part of #40366. Fix a number of javac issues when linting is enforced in server/. Due to the number of issues that this surfaces, the fixes will be spread of multiple PRs.

@pugnascotia pugnascotia requested a review from mark-vieira July 28, 2021 15:10
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Jul 28, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

@pugnascotia
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/bwc

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

Left a few questions but otherwise LGTM.

@@ -158,7 +158,7 @@ public void collect(int doc, long bucket) throws IOException {
}

@Override
LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) {
LeafBucketCollector getLeafCollector(Comparable<?> value, LeafReaderContext context, LeafBucketCollector next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In cases like this, shouldn't use Comparable<Double> here so we can enforce this at compile time instead of adding an explicit runtime check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, we need to update this method on SingleDimensionValuesSource to use the proper generic type argument instead of a wildcard. We probably have missed this in other areas as well. We should go back and check where we've used wildcards that there isn't already a proper type argument we should be using instead.

@@ -97,7 +97,7 @@ public String getPreferredName() {
private DateHistogramInterval dateHistogramInterval;
private IntervalTypeEnum intervalType = IntervalTypeEnum.NONE;

public static <T extends DateIntervalConsumer> void declareIntervalFields(ObjectParser<T, String> parser) {
public static <T extends DateIntervalConsumer<T>> void declareIntervalFields(ObjectParser<T, String> parser) {
Copy link
Contributor

Choose a reason for hiding this comment

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

AGain, shouldn't this be T extends DateIntervalConsumer<?>>? Am I not understanding this properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's one of these super-confusing recursive types. I think it's correct.

@@ -434,6 +434,7 @@ public static Aggregator buildWithoutAttemptedToAdaptToFilters(
private final DocValueFormat format;
protected final Range[] ranges;
private final boolean keyed;
@SuppressWarnings("rawtypes")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it we don't just use wildcard types in these scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You get into the situation of ? being different from ?. It's a mess.

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

Added a few more comments.

@@ -100,7 +100,7 @@
/**
* Sets the after value for this source. Values that compares smaller are filtered.
*/
abstract void setAfter(Comparable value);
abstract void setAfter(Comparable<?> value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Comparable<T> IMO since this type is already generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done as you suggest, though all the implementations seem to handle arguments other than T, so I'm not 100% sure it's correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I see now. Looks like we are lenient here in places and will accept string values. Given that everything compiles though that must imply we're doing either casting or reflection to call this with other types somewhere. Should be fine given type erasure but if the implementations expect other types we should allow it at compile time I suppose 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked more carefully at how this method is called, and ended up reverting the wildcard replacement. It's "correct" given the implementations 🤷

@@ -158,7 +158,7 @@ public void collect(int doc, long bucket) throws IOException {
}

@Override
LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) {
LeafBucketCollector getLeafCollector(Comparable<?> value, LeafReaderContext context, LeafBucketCollector next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, we need to update this method on SingleDimensionValuesSource to use the proper generic type argument instead of a wildcard. We probably have missed this in other areas as well. We should go back and check where we've used wildcards that there isn't already a proper type argument we should be using instead.

@@ -162,7 +162,7 @@ public void collect(int doc, long bucket) throws IOException {
}

@Override
LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) {
LeafBucketCollector getLeafCollector(Comparable<?> value, LeafReaderContext context, LeafBucketCollector next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here, assuming we update SingleDimensionValuesSource we should make this Comparable<BytesRef>

@pugnascotia
Copy link
Contributor Author

@elasticmachine update branch

@pugnascotia pugnascotia merged commit 4bfead0 into elastic:master Aug 2, 2021
@pugnascotia pugnascotia deleted the 40366-lint-warnings-server-pt2 branch August 2, 2021 14:45
pugnascotia added a commit that referenced this pull request Aug 2, 2021
Part of #40366. Fix a number of javac issues when linting is enforced in `server/`.
@pugnascotia
Copy link
Contributor Author

Backported to 7.x in f3161a2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >refactoring Team:Delivery Meta label for Delivery team v7.15.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants