-
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 Error Prone code style verification #632
Conversation
3a512c6
to
adbabaf
Compare
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.
Hello @vlsi ,
Thanks for this PR.
Just few notes.
Regards
@@ -80,7 +82,7 @@ public static void main(String [] args) throws Exception{ | |||
private static void sendLine( String line, OutputStream outPipe ) | |||
throws IOException | |||
{ | |||
outPipe.write( line.getBytes() ); // TODO - charset? | |||
outPipe.write(line.getBytes(StandardCharsets.UTF_8)); |
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.
Are you sure about the potential breaks this might introduce ?
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 believe there's a movement to use UTF-8 by default.
- https://openjdk.java.net/jeps/8187041
- Kotlin uses UTF-8 by default: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/read-text.html
Of course, we can make it configurable, however, I believe, most of the times UTF-8 by default would be better (less chances to corrupt data) than use platform-default encoding.
ec9db99
to
967ac65
Compare
Codecov Report
@@ Coverage Diff @@
## master #632 +/- ##
============================================
+ Coverage 55.30% 55.35% +0.04%
+ Complexity 10091 10088 -3
============================================
Files 1038 1036 -2
Lines 63858 63779 -79
Branches 7229 7212 -17
============================================
- Hits 35314 35302 -12
+ Misses 26049 25983 -66
+ Partials 2495 2494 -1
Continue to review full report at Codecov.
|
@pmouawad , the PR passes tests, and it looks like it is ready for review and merge. |
src/components/src/main/java/org/apache/jmeter/assertions/XMLAssertion.java
Outdated
Show resolved
Hide resolved
My biggest concern with this PR at the moment is its size. Could we add the feature (errorprone) without changing every nag it shows? I tend to get bored when looking at big PRs and either skip parts, or abort looking at it altogether. |
All the previous CI jobs pass, so it works.
Well, most of the warnings are true issues. There is an unfortunate case when the tool discourages the use of |
See https://errorprone.info/ It allows to capture errors like mising switch case branches, missing override, non-static inner class, etc The verification can be run locally via ./gradlew -PenableErrorprone classes Note: Java 11+ is required
…plerContext, DynamicClassLoader
JUnitAmbiguousTestClass is intentional there
8f65ce9
to
2421808
Compare
Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to See https://errorprone.info/bugpattern/BadImport
The code contains too many JavaDoc warnings
In all the cases Enumeration comes from Java interfaces, so we can't avoid it. Unfortunately error-prone does not recognize that yet. See google/error-prone#1646
It would be nice to migrate to java.time API, so the idea is to suppress the current usages, and use newer APIs for the new code.
error-prone requires the comment
Most of the times, the returned Future objects must not be ignored. DiskStoreSampleSender should probably be reworked to propagate exceptions.
Unfortunately, error-prone can't detect that false positive yet
int += long pattern hides a lossy cast, so it is better to write that explicitly
See https://errorprone.info/
It allows to capture errors like mising switch case branches,
missing override, non-static inner class, etc
The verification can be run locally via ./gradlew -PenableErrorprone classes
Note: Java 11+ is required
The changes do not seem to be very big for me, however, it seems to flag important issues: it forbids the use of deprecated methods, it flags the use of the default encoding, it suggests to avoid
LinkedList
, and so on.I fixed the warnings by running
classes -PenableErrorprone -Pwerror=false --rerun-tasks
in my IDE, so it printed all the warnings, then I could click on each error to navigate and resolve it.The biggest commits are
91851b1 Replace LinkedList with ArrayList
89 files changed, 249 insertions(+), 241 deletions(-)
d668dd3 Remove uses of deprecated APIs
52 files changed, 154 insertions(+), 90 deletions(-)
be8438d Suppress DefaultCharset usage: either suppress the warning or use a charset
27 files changed, 85 insertions(+), 94 deletions(-)