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

Enable most IntelliJ 'Probable bugs' inspections #4353

Merged
merged 9 commits into from
Jun 7, 2017

Conversation

leventov
Copy link
Member

@leventov leventov commented Jun 2, 2017

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:

  • Fix IndexSpec.equals() and hashCode() to include longEncoding
  • calling toString() on objects of classes which don't override toString()
  • instance fields which should really be static final fields
  • unnecessary use of | and & instead of || and &&.

// this value should never be set for production data
private final DateTime missingValue;
private final transient Function<Object, DateTime> timestampConverter;
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought transient just marks fields that shouldn't be serialized. But this class isn't Serializable, so what's the point?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@@ -27,7 +27,7 @@
*/
public class IntegerPartitionChunk<T> implements PartitionChunk<T>
{
Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst();
private static final Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst();
Copy link
Contributor

Choose a reason for hiding this comment

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

static field should be all-caps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed field

@@ -25,7 +25,7 @@

public class LinearPartitionChunk <T> implements PartitionChunk<T>
{
Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst();
private static final Comparator<Integer> comparator = Ordering.<Integer>natural().nullsFirst();
Copy link
Contributor

Choose a reason for hiding this comment

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

static field should be all-caps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed field

@@ -1349,10 +1349,12 @@ boolean needConversion(int index)
{
IntBuffer readOnly = conversions[index].asReadOnlyBuffer();
readOnly.rewind();
for (int i = 0; readOnly.hasRemaining(); i++) {
int i = 0;
while (readOnly.hasRemaining()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What prompted this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it.

@@ -32,7 +32,7 @@
*/
public class BitmapCompressedIndexedInts implements IndexedInts, Comparable<ImmutableBitmap>
{
private static Ordering<ImmutableBitmap> comparator = new Ordering<ImmutableBitmap>()
private static final Ordering<ImmutableBitmap> comparator = new Ordering<ImmutableBitmap>()
Copy link
Contributor

Choose a reason for hiding this comment

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

comparator should be all-caps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed

@gianm
Copy link
Contributor

gianm commented Jun 7, 2017

Looks good to me, 👍 after CI passes.

@leventov leventov added the WIP label Jun 7, 2017
@leventov leventov removed the WIP label Jun 7, 2017
@leventov
Copy link
Member Author

leventov commented Jun 7, 2017

Decided to use IntelliJ-style noinspection comments to suppress IntelliJ-specific inspections, instead of @SuppressWarnings on a method, because the scope of suppression is narrower and it's obvious why suppression is added -- the reason is on the next line. It doesn't matter that those comments are "non-standard", because no other tools or IDEs like Eclipse are able to understand the suppression reasons anyway.

@@ -506,16 +506,18 @@ public void read(ByteBuffer buffer, ColumnBuilder builder, ColumnConfig columnCo
)
{
switch (version) {
case UNCOMPRESSED_MULTI_VALUE:
case UNCOMPRESSED_MULTI_VALUE: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we've ever had this rule before, where is it enforced?

Copy link
Member Author

Choose a reason for hiding this comment

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

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)));
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

was the prior way just a hack to get over the fact that this was doing an n^2 search?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@@ -120,7 +120,7 @@ public String toString()
{
return "FireHydrant{" +
"index=" + index +
", queryable=" + adapter +
", queryable=" + adapter.getIdentifier() +
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because ReferenceCountingSegment doesn't override Object.toString(), so FireHydrant's String form looks like .., queryable=ReferenceCountingSegment@hash, .. - not useful.

@drcrallen drcrallen merged commit 63a897c into apache:master Jun 7, 2017
@drcrallen drcrallen deleted the more-intellij-inspections branch June 7, 2017 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants