Skip to content
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

Merged
merged 40 commits into from
Oct 31, 2020
Merged

Add Error Prone code style verification #632

merged 40 commits into from
Oct 31, 2020

Conversation

vlsi
Copy link
Collaborator

@vlsi vlsi commented Oct 18, 2020

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(-)

@vlsi vlsi force-pushed the errorprone branch 2 times, most recently from 3a512c6 to adbabaf Compare October 18, 2020 13:15
Copy link
Contributor

@pmouawad pmouawad left a 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));
Copy link
Contributor

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 ?

Copy link
Collaborator Author

@vlsi vlsi Oct 18, 2020

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.

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.

src/jorphan/src/main/java/org/apache/log/ContextMap.java Outdated Show resolved Hide resolved
@vlsi vlsi force-pushed the errorprone branch 9 times, most recently from ec9db99 to 967ac65 Compare October 18, 2020 21:28
@codecov-io
Copy link

Codecov Report

Merging #632 into master will increase coverage by 0.04%.
The diff coverage is 68.27%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...n/java/org/apache/jmeter/util/BeanShellClient.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...va/org/apache/jmeter/assertions/HTMLAssertion.java 20.56% <0.00%> (ø) 15.00 <0.00> (ø)
...org/apache/jmeter/config/RandomVariableConfig.java 71.42% <ø> (ø) 23.00 <0.00> (ø)
...va/org/apache/jmeter/control/ModuleController.java 70.12% <ø> (ø) 21.00 <0.00> (ø)
...ctor/json/render/AbstractRenderAsJsonRenderer.java 84.21% <0.00%> (ø) 18.00 <0.00> (ø)
...er/extractor/json/render/RenderAsJsonRenderer.java 91.30% <ø> (ø) 9.00 <0.00> (ø)
...ava/org/apache/jmeter/modifiers/CounterConfig.java 91.02% <ø> (ø) 35.00 <0.00> (ø)
...va/org/apache/jmeter/modifiers/UserParameters.java 64.00% <0.00%> (ø) 15.00 <0.00> (ø)
...a/org/apache/jmeter/timers/PoissonRandomTimer.java 72.97% <ø> (-5.41%) 9.00 <0.00> (-1.00)
...issonarrivals/ConstantPoissonProcessGenerator.java 58.57% <ø> (ø) 14.00 <0.00> (ø)
... and 284 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d34a52...967ac65. Read the comment docs.

@vlsi
Copy link
Collaborator Author

vlsi commented Oct 18, 2020

@pmouawad , the PR passes tests, and it looks like it is ready for review and merge.

extras/startup.bsh Outdated Show resolved Hide resolved
@FSchumacher
Copy link
Contributor

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.
Apart from that, I am +1 on adding the feature (if it doesn't break the build when running with Java 8). (Haven't tried it)

@vlsi
Copy link
Collaborator Author

vlsi commented Oct 21, 2020

if it doesn't break the build when running with Java 8

All the previous CI jobs pass, so it works.
In practice, it is activated only in case -PenableErrorprone is added as a command-line option or gradle.properties setting.

Could we add the feature (errorprone) without changing every nag it shows?

Well, most of the warnings are true issues. There is an unfortunate case when the tool discourages the use of Hashtable, Enumeration, and LinkedList in the same check.
Nobody uses Hashtable nowadays unless that is required for an ancient API, however, people can easily use LinkedList without realizing it is way slower and less efficient than ArrayList and ArrayDeque

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
@vlsi vlsi force-pushed the errorprone branch 2 times, most recently from 8f65ce9 to 2421808 Compare October 31, 2020 11:28
vlsi added 28 commits October 31, 2020 15:58
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
@vlsi vlsi merged commit 150a275 into apache:master Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants