Enable most IntelliJ 'Probable bugs' inspections#4353
Enable most IntelliJ 'Probable bugs' inspections#4353drcrallen merged 9 commits intoapache:masterfrom
Conversation
| private final Function<Object, DateTime> timestampConverter; | ||
| // this value should never be set for production data | ||
| private final DateTime missingValue; | ||
| private final transient Function<Object, DateTime> timestampConverter; |
There was a problem hiding this comment.
I thought transient just marks fields that shouldn't be serialized. But this class isn't Serializable, so what's the point?
There was a problem hiding this comment.
It was for indication that this field is not checked in equals() and hashCode(). But that was a bad way, removed transient and added a simple comment.
| public class IntegerPartitionChunk<T> implements PartitionChunk<T> | ||
| { | ||
| Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst(); | ||
| private static final Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst(); |
There was a problem hiding this comment.
static field should be all-caps.
| public class LinearPartitionChunk <T> implements PartitionChunk<T> | ||
| { | ||
| Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst(); | ||
| private static final Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst(); |
There was a problem hiding this comment.
static field should be all-caps.
| readOnly.rewind(); | ||
| for (int i = 0; readOnly.hasRemaining(); i++) { | ||
| int i = 0; | ||
| while (readOnly.hasRemaining()) { |
There was a problem hiding this comment.
There is an inspection that checks that loop variable is checked in condition part of for loop. This occasion was a false positive, and I think it's better to reformat code than add @SuppressWarnings
| public class BitmapCompressedIndexedInts implements IndexedInts, Comparable<ImmutableBitmap> | ||
| { | ||
| private static Ordering<ImmutableBitmap> comparator = new Ordering<ImmutableBitmap>() | ||
| private static final Ordering<ImmutableBitmap> comparator = new Ordering<ImmutableBitmap>() |
There was a problem hiding this comment.
comparator should be all-caps.
|
Looks good to me, 👍 after CI passes. |
|
Decided to use IntelliJ-style |
| { | ||
| switch (version) { | ||
| case UNCOMPRESSED_MULTI_VALUE: | ||
| case UNCOMPRESSED_MULTI_VALUE: { |
There was a problem hiding this comment.
I don't think we've ever had this rule before, where is it enforced?
There was a problem hiding this comment.
This change is a workaround for false positive inspection (due to a defect in the inspection itself). The inspection tracks for "false indentation", e. g.
for (int i : array)
actionOne();
actionTwo();Because I may think that both actionOne() and actionTwo() are executed in the loop, and I forgot braces.
In this case, inspection thinks that block
default:
throw new IAE("Unsupported multi-value version[%s]", version); throw new IAE("Unsupported multi-value version[%s]", version);should have deeper indentation, because the previous case doesn't have break; in the end. But if fails to see that all brances in if-else chain break the control flow (two returns and one throw).
| } | ||
| for (int i = 0; i < keys.size(); i++) { | ||
| for (int j = i + 1; j < keys.size(); j++) { | ||
| assertFalse(Arrays.equals(keys.get(i), keys.get(j))); |
There was a problem hiding this comment.
this logic changes if I'm reading it correctly. Previously if k1 and k2 were the same object, this would not fail. But now it will fail.
There was a problem hiding this comment.
was the prior way just a hack to get over the fact that this was doing an n^2 search?
There was a problem hiding this comment.
As far as I understand, the previous version was looking for duplicates in the keys list. Condition k1 != k2 was filtering "the diagonal" in n^2 search, but it was unreliable. Anyway, I had to change this piece of code because inspection about array reference comparison.
| return "FireHydrant{" + | ||
| "index=" + index + | ||
| ", queryable=" + adapter + | ||
| ", queryable=" + adapter.getIdentifier() + |
There was a problem hiding this comment.
Because ReferenceCountingSegment doesn't override Object.toString(), so FireHydrant's String form looks like .., queryable=ReferenceCountingSegment@hash, .. - not useful.
Enable "Error" severity for most IntelliJ inspections of "Probable bugs" category which don't catch anything at the moment. Inspections, which have a lot of matches in the codebase, are left on "Warning" level, to keep this PR small. The latter inspections should be moved to "Error" level one-by-one in separate PRs.
A few real (but minor) defects are fixed in the code:
IndexSpec.equals()andhashCode()to includelongEncoding|and&instead of||and&&.