-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-25986][Build] Add rules to ban throw Errors in application code #22989
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
Conversation
Test build #98637 has finished for PR 22989 at commit
|
retest this please. |
Test build #98649 has finished for PR 22989 at commit
|
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.
Where is it thrown directly though?
Honestly it is bad style to throw any Error class, except in sepcial situations. I'd prefer a rule banning all of these and fix up any instances in the code or else exclude them |
and catching Error or Throwable.. |
dev/checkstyle.xml
Outdated
@@ -64,6 +64,11 @@ | |||
<property name="message" value="No trailing whitespace allowed."/> | |||
</module> | |||
|
|||
<module name="RegexpSingleline"> | |||
<property name="format" value="throw new OutOfMemoryError"/> |
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.
Per my suggestion below, how about the regex throw new \\w+Error\\(
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.
Thanks, done in 6e49bb8.
Sorry for late reply, great thanks for all reviewer's advise, will address them soon. |
cc all reviewer, as @srowen's suggestion, add a rule to ban all of new Error cases.
|
Test build #98731 has finished for PR 22989 at commit
|
The I would fix the Agree about the rest. Thanks for the great analysis @xuanyuanking |
@srowen Great thanks for your guidance, address all your suggestion in ff234d3 and update the record table in #22989 (comment). |
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.
Looks quite good to me, just a few comments.
dev/checkstyle-suppressions.xml
Outdated
@@ -46,4 +46,12 @@ | |||
files="sql/catalyst/src/main/java/org/apache/spark/sql/streaming/GroupStateTimeout.java"/> | |||
<suppress checks="MethodName" | |||
files="sql/core/src/main/java/org/apache/spark/sql/streaming/Trigger.java"/> | |||
<suppress checks="RegexpSingleline" |
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 might suppress many checks? is it difficult to suppress with comments in these files?
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.
Yep, I met some problem during suppress with comments, just work around by suppress files, I will find the problem again.
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 found the problem is RegexpSingleline
can't put into TreeWalker
, so SuppressionCommentFilter
rule can't effect on it, RegexpSinglelineJava
is the right choice. Also spend some time on comment syntax, maybe the usage description can be improved a little, please have a check whether I understand this rule correctly. Done in a4f49ce.
mllib/src/test/scala/org/apache/spark/ml/feature/VectorIndexerSuite.scala
Outdated
Show resolved
Hide resolved
Test build #98749 has finished for PR 22989 at commit
|
Test build #98770 has finished for PR 22989 at commit
|
mllib/src/test/scala/org/apache/spark/mllib/clustering/KMeansSuite.scala
Outdated
Show resolved
Hide resolved
@@ -180,5 +180,10 @@ | |||
<module name="UnusedImports"/> | |||
<module name="RedundantImport"/> | |||
<module name="RedundantModifier"/> | |||
<module name="RegexpSinglelineJava"> | |||
<property name="format" value="throw new \w+Error\("/> | |||
<property name="message" value="Avoid throwing error in application code."/> |
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 application code
means 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.
application code
against JVM here, as Error subclasses generally represent internal JVM errors.
Test build #98826 has finished for PR 22989 at commit
|
Merged to master |
Thanks @HyukjinKwon @viirya @felixcheung @srowen for your review and advise! |
@@ -39,7 +39,9 @@ public static int getSize(Object object, long offset) { | |||
case 8: | |||
return (int)Platform.getLong(object, offset); | |||
default: | |||
// checkstyle.off: RegexpSinglelineJava | |||
throw new AssertionError("Illegal UAO_SIZE"); |
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.
shall we throw IllegalStateException
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.
I think these are ok as AssertionError because they shouldn't be able to happen in any JVM state
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.
yea, that's exactly the use case of IllegalStateException
, which can also pass the style check 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 would be OK too. This is just picking nits now but I thought AssertionError was still better. ISE is about application state. Errors are about JVM state.
@@ -52,7 +54,9 @@ public static void putSize(Object object, long offset, int value) { | |||
Platform.putLong(object, offset, value); | |||
break; | |||
default: | |||
// checkstyle.off: RegexpSinglelineJava | |||
throw new AssertionError("Illegal UAO_SIZE"); |
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.
ditto
## What changes were proposed in this pull request? Add scala and java lint check rules to ban the usage of `throw new xxxErrors` and fix up all exists instance followed by apache#22989 (comment). See more details in apache#22969. ## How was this patch tested? Local test with lint-scala and lint-java. Closes apache#22989 from xuanyuanking/SPARK-25986. Authored-by: Yuanjian Li <[email protected]> Signed-off-by: Sean Owen <[email protected]>
What changes were proposed in this pull request?
Add scala and java lint check rules to ban the usage of
throw new xxxErrors
and fix up all exists instance followed by #22989 (comment). See more details in #22969.How was this patch tested?
Local test with lint-scala and lint-java.