-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 error-prone static analysis checks #961
Changes from all commits
c66f692
cc48c98
a9efe7e
34573c2
387a662
0e770db
adbeeaa
ed3f5ce
630719b
fd74fea
c66367d
3e75ef9
95e235a
c08c189
038e789
8bca358
31add43
2beb69b
fe8c123
20bac2e
bdec69c
82767e8
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 |
---|---|---|
|
@@ -58,6 +58,9 @@ private Assertions() { | |
* <p>See Javadoc for {@link #fail(String, Throwable)} for an explanation of | ||
* this method's generic return type {@code V}. | ||
*/ | ||
// we purposely return a V that has nothing to do with the parameters of this method; see | ||
// the javadoc for details. | ||
@SuppressWarnings("TypeParameterUnusedInFormals") | ||
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. Where does this warning come from? It looks non-standard to me. 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. It is indeed non-standard. It's an error-prone warning. I added it here because I thought that there weren't enough false positives to justify disabling the corresponding error-prone rule "TypeParameterUnusedInFormals" globally. If you disagree, I'd be happy to disable "TypeParameterUnusedInFormals" by adding ""-Xep:TypeParameterUnusedInFormals:OFF" to the 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. For more info on the rule, see http://errorprone.info/bugpattern/TypeParameterUnusedInFormals. 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. I'm simply hesitant to introduce all of these Is there not a more elegant way to achieve this without introducing 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. Unfortunately, I don't think there is a more elegant way. AFAICT, it's the only solution that the docs for that rule provides. (The docs for all the other rules I've looked at in the past suggest the exact same workaround, IIRC) 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. @sbrannen We have two options AFAICT:
I'm personally not a fan of disabling the rule, because according the bug patterns docs (type Ctrl+F and search for "TypeParameterUnusedInFormals"), it's a default non-experimental rule, which suggests to me that it's worth keeping on. But on the other hand, I empathise with you on annoying warnings in IDEs, so if it really does drive you round the bend, then I'd be happy to disable it. 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. MMmmm.... ok. Well, my sanity is not paramount here. 😇 So let's see how it goes once all of this is in place. |
||
public static <V> V fail(String message) { | ||
AssertionUtils.fail(message); | ||
return null; // appeasing the compiler: this line will never be executed. | ||
|
@@ -78,6 +81,9 @@ public static <V> V fail(String message) { | |
* Stream.of().map(entry -> fail("should not be called")); | ||
* }</pre> | ||
*/ | ||
// we purposely return a V that has nothing to do with the parameters of this method; see | ||
// the javadoc for details. | ||
@SuppressWarnings("TypeParameterUnusedInFormals") | ||
public static <V> V fail(String message, Throwable cause) { | ||
AssertionUtils.fail(message, cause); | ||
return null; // appeasing the compiler: this line will never be executed. | ||
|
@@ -89,6 +95,9 @@ public static <V> V fail(String message, Throwable cause) { | |
* <p>See Javadoc for {@link #fail(String, Throwable)} for an explanation of | ||
* this method's generic return type {@code V}. | ||
*/ | ||
// we purposely return a V that has nothing to do with the parameters of this method; see | ||
// the javadoc for details. | ||
@SuppressWarnings("TypeParameterUnusedInFormals") | ||
public static <V> V fail(Throwable cause) { | ||
AssertionUtils.fail(cause); | ||
return null; // appeasing the compiler: this line will never be executed. | ||
|
@@ -101,6 +110,9 @@ public static <V> V fail(Throwable cause) { | |
* <p>See Javadoc for {@link #fail(String, Throwable)} for an explanation of | ||
* this method's generic return type {@code V}. | ||
*/ | ||
// we purposely return a V that has nothing to do with the parameters of this method; see | ||
// the javadoc for details. | ||
@SuppressWarnings("TypeParameterUnusedInFormals") | ||
public static <V> V fail(Supplier<String> messageSupplier) { | ||
AssertionUtils.fail(messageSupplier); | ||
return null; // appeasing the compiler: this line will never be executed. | ||
|
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.
Why did you move this method?
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 moved it because, before I added "-Xep:UngroupedOverloads:OFF" to the
build.gradle
file, error-prone reported that methods like this one were not 'grouped' together with methods of the same name, potentially causing confusion for future maintainers.I ultimately added "-Xep:UngroupedOverloads:OFF" to the
build.gradle
because the corresponding rule produced a lot of churn for little gain, but as I was reverting the changes I made initially to satisfy the rule, I thought that moving all thefloatsAreEqual()
methods together made a great deal of sense, so I decided to keep it.If you want me to move it back to where it was, or to put this change in a new PR, please let me know!
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.
You can leave it "as is" for the time being.