-
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
Changes from all commits
d678751
6e49bb8
ff234d3
a4f49ce
210d942
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
// checkstyle.on: RegexpSinglelineJava | ||
} | ||
} | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
// checkstyle.on: RegexpSinglelineJava | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,13 +71,13 @@ | |
If you wish to turn off checking for a section of code, you can put a comment in the source | ||
before and after the section, with the following syntax: | ||
|
||
// checkstyle:off no.XXX (such as checkstyle.off: NoFinalizer) | ||
// checkstyle.off: XXX (such as checkstyle.off: NoFinalizer) | ||
... // stuff that breaks the styles | ||
// checkstyle:on | ||
// checkstyle.on: XXX (such as checkstyle.on: NoFinalizer) | ||
--> | ||
<module name="SuppressionCommentFilter"> | ||
<property name="offCommentFormat" value="checkstyle.off\: ([\w\|]+)"/> | ||
<property name="onCommentFormat" value="checkstyle.on\: ([\w\|]+)"/> | ||
<property name="offCommentFormat" value="checkstyle\.off\: ([\w\|]+)"/> | ||
<property name="onCommentFormat" value="checkstyle\.on\: ([\w\|]+)"/> | ||
<property name="checkFormat" value="$1"/> | ||
</module> | ||
<module name="OuterTypeFilename"/> | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. What There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</module> | ||
|
||
</module> | ||
</module> |
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.