Skip to content

Conversation

@kiszk
Copy link
Member

@kiszk kiszk commented Dec 31, 2018

What changes were proposed in this pull request?

This PR addresses warning messages in Java files reported at lgtm.com.

lgtm.com provides automated code review of Java/Python/JavaScript files for OSS projects. Here are warning messages regarding Apache Spark project.

This PR addresses the following warnings:

  • Result of multiplication cast to wider type
  • Implicit narrowing conversion in compound assignment
  • Boxed variable is never null
  • Useless null check

NOTE: Potential input resource leak looks false positive for now.

How was this patch tested?

Existing UTs

Copy link
Member

Choose a reason for hiding this comment

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

Is this safe change? Looks like behavior change when throwing exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, this is my mistake. I will revert this.

Copy link
Member

Choose a reason for hiding this comment

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

We need a space after casts. I suppose the point is to avoid overflow when the result is going to be a double anyway, at the cost of precision maybe. I tested, and the precision issue won't matter, but then again, there's no reason this method should return double. There is no such thing as 0.5 bytes.

I think we can just fix that for Spark 3; its value is used as a long or int everywhere anyway.

While here, I think I'd also fix the expressions like (long) Math.pow(1024L, 2L) above. The multipliers should be 1L << 10, 1L << 20, ... 1L << 50. There's again no point there in using floating point math.

Copy link
Member Author

@kiszk kiszk Dec 31, 2018

Choose a reason for hiding this comment

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

I agree with chaniging the precision. I will use long here.
I will also use 1L << 10, ... in enum ByteUnit.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, really? what does it return? type-wise the numbers should easily fit into a long. 2 TiB = 2199023255552 bytes. I'm missing where the failure is here.

Copy link
Member

Choose a reason for hiding this comment

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

Write 100.0 here for extra clarity, and put spaces after all the casts here. Otherwise, what's the issue with this expression?

Copy link
Member Author

Choose a reason for hiding this comment

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

lgtm.com and I are afraind (...) * chunkFetchHandlerThreadsPercent may cause overflow since it is int * int. After this change, it will be double * double.

Copy link
Member

Choose a reason for hiding this comment

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

Oh it's because it's really (threads * percent) / 100. Maybe this can be simplified by breaking out the (this.serverThreads() ...) into a local variable, then writing as threads * (percent / 100.0)

Copy link
Contributor

Choose a reason for hiding this comment

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

oops looks like I missed this comment, sorry for the duplicate.

Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of 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.

ditto, I will revert this.

Copy link
Member

Choose a reason for hiding this comment

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

I'd put the cast on line 183 and make n an int. length and next are nonnegative ints.

Copy link
Member Author

Choose a reason for hiding this comment

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

i see

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 probably just improve this by creating this class name string once above line 321, and putting something like "no message" instead of null, while we're here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@SparkQA
Copy link

SparkQA commented Dec 31, 2018

Test build #100588 has finished for PR 23420 at commit 34f0008.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@kiszk kiszk closed this Dec 31, 2018
@kiszk kiszk deleted the SPARK-26508 branch December 31, 2018 16:03
@kiszk kiszk restored the SPARK-26508 branch December 31, 2018 16:05
@kiszk
Copy link
Member Author

kiszk commented Dec 31, 2018

reopen this

@kiszk kiszk reopened this Dec 31, 2018
@kiszk
Copy link
Member Author

kiszk commented Dec 31, 2018

retest this please

@SparkQA
Copy link

SparkQA commented Dec 31, 2018

Test build #100598 has finished for PR 23420 at commit cf5c927.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@holdenk holdenk left a comment

Choose a reason for hiding this comment

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

I'm not sure about the cast with the division, could we simplify it?

return (int)Math.ceil(
(this.serverThreads() > 0 ? this.serverThreads() : 2 * NettyRuntime.availableProcessors()) *
chunkFetchHandlerThreadsPercent/(double)100);
(double) chunkFetchHandlerThreadsPercent/100);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure about moving this cast, why are doing that? Would it make more sense to write this as chunkFetchHandlerThreadsPercent / 100.0 ?

fix test failure
@SparkQA
Copy link

SparkQA commented Jan 1, 2019

Test build #100606 has finished for PR 23420 at commit 557a940.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@kiszk
Copy link
Member Author

kiszk commented Jan 1, 2019

retest this please

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

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

Looks fine pending tests, with one tiny request


private long getElementOffset(int ordinal) {
return startingOffset + headerInBytes + ordinal * elementSize;
return startingOffset + headerInBytes + ordinal * (long)elementSize;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: space after cast

@SparkQA
Copy link

SparkQA commented Jan 1, 2019

Test build #100623 has finished for PR 23420 at commit 557a940.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 2, 2019

Test build #100628 has finished for PR 23420 at commit 3df0a0a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member

srowen commented Jan 2, 2019

Merged to master

@srowen srowen closed this in 79b0548 Jan 2, 2019
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
… lgtm.com

## What changes were proposed in this pull request?

This PR addresses warning messages in Java files reported at [lgtm.com](https://lgtm.com).

[lgtm.com](https://lgtm.com) provides automated code review of Java/Python/JavaScript files for OSS projects. [Here](https://lgtm.com/projects/g/apache/spark/alerts/?mode=list&severity=warning) are warning messages regarding Apache Spark project.

This PR addresses the following warnings:

- Result of multiplication cast to wider type
- Implicit narrowing conversion in compound assignment
- Boxed variable is never null
- Useless null check

NOTE: `Potential input resource leak` looks false positive for now.

## How was this patch tested?

Existing UTs

Closes apache#23420 from kiszk/SPARK-26508.

Authored-by: Kazuaki Ishizaki <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants