-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add errorprone verifications #5873
Conversation
48ead5b
to
4ca844f
Compare
build-logic/verification/src/main/kotlin/build-logic.errorprone.gradle.kts
Outdated
Show resolved
Hide resolved
@@ -126,8 +126,8 @@ private void compareContent(CompareAssertionResult result) { | |||
} | |||
} | |||
|
|||
private void markContentFailure(CompareAssertionResult result, String prevContent, SampleResult prevResult, | |||
SampleResult currentResult, String currentContent) { | |||
private static void markContentFailure(CompareAssertionResult result, String prevContent, SampleResult prevResult, |
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.
In my current IDE setup, the IDE suggests this kind of change quite often and I wonder why. Is it better performing, more stylish, something else?
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.
The key feature is that static
keyword makes it clear that the method does not access instance
fields, so all the variables are local
src/components/src/main/java/org/apache/jmeter/visualizers/SearchTextExtension.java
Show resolved
Hide resolved
@@ -102,7 +102,6 @@ protected boolean popupCheckExistingFileListener(HashTree tree) { | |||
return false; | |||
} | |||
case ASK: | |||
default: |
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.
While it might not be nice to have a fall-through from ASK
to default
. Removing default seems wrong (haven't looked deeply into this).
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.
The removal of default fo enums
is indeed the most controversial changes here.
However, in this case, the switch goes over private enum
:
private enum ActionOnFile {
APPEND,
DELETE,
ASK
}
So it is clear there are only three possibilities, so the default can be omitted.
At the same time, if some of enum cases are missing, the compilation would fail.
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.
The questionable part is whether we trust enums from third-party classes. In other words, even if we cover all the current cases, it might be the library would add a new case, so if users upgrade the library without recompiling jmeter, then it won't detect "unexpected enum value".
WDYT? Is it really that important?
Frankly speaking, I thin that an exhaustive switch over enum values looks better than arbitrary default that might unexpectedly catch newly added enum values. In other words, if we omit default for enums, then the newly added value would fail the compilation and ask the developer to add an appropriate case rather than falling into an unknown default.
src/core/src/main/java/org/apache/jmeter/report/processor/ExternalSampleSorter.java
Show resolved
Hide resolved
@@ -175,8 +175,6 @@ static synchronized void logDetails(Logger logger, String stringToLog, String pr | |||
case TRACE: | |||
logger.trace("{} {} {}", threadName, separator, stringToLog, throwable); | |||
break; | |||
default: |
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.
Seems wrong to be removed.
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.
Do you really think we should protect from the case when org.slf4j.event.Level
enum will have extra enum value in runtime?
I think it would be unlikely, and if we drop the default, then we'll know when slf4j adds new value in compile-time.
@Override | ||
@SuppressWarnings("deprecation") | ||
public void finalize() throws Throwable { | ||
dispose(); |
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.
Can we remove this already? Do we have to take care of dspose() somewhere else?
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.
Finalize runs whenever the object becomes unreachable. Currently, MenuScroller
is discarded as soon as it is created. I believe this finalize
has never been useful.
@@ -181,8 +181,6 @@ public void tag(Tag tag) { | |||
break; | |||
case END: | |||
break; | |||
default: |
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.
Seems wrong to remove
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.
This is a switch over jodd.lagarto.TagType
enum. The current switch covers all enum cases.
I think it would be better to ensure enum switches are exhaustive rather than fail in runtime.
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
Show resolved
Hide resolved
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
Show resolved
Hide resolved
…mpiler only ErrorProne requires Java 11, so we can't execute it with Java 8 compiler.
The redundant overrides for clone are left intact as they are needed for Sonar rule S2157 - "Cloneables" should implement "clone"
d5bc20f
to
453b470
Compare
See https://errorprone.info/bugpattern/FieldCanBeStatic # Conflicts: # build-logic/verification/src/main/kotlin/build-logic.errorprone.gradle.kts
There's no much sense in alignling the parameters just like with most the other cases for horizontal alignment. See https://google.github.io/styleguide/javaguide.html#s4.6.3-horizontal-alignment
The code changes are performed using two approaches:
In other words, there are no changes that were made "just in case", and the code changes are accompanied with the corresponding Errorprone verifications, so we won't accidentally re-introduce the same issues.