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 errorprone verifications #5873

Merged
merged 11 commits into from
May 5, 2023
Merged

Add errorprone verifications #5873

merged 11 commits into from
May 5, 2023

Conversation

vlsi
Copy link
Collaborator

@vlsi vlsi commented May 1, 2023

The code changes are performed using two approaches:

  1. IDEA's "run inspection by name". "field may be static", "field may be final", "method may be static", "replace iterator with foreach"
  2. Manual edits driven by Errorprone failures: remove default cases in enum switch, and some of "method may be static"

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.

@vlsi vlsi force-pushed the errorprone branch 2 times, most recently from 48ead5b to 4ca844f Compare May 1, 2023 13:48
@@ -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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@@ -102,7 +102,6 @@ protected boolean popupCheckExistingFileListener(HashTree tree) {
return false;
}
case ASK:
default:
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@vlsi vlsi May 1, 2023

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.

@@ -175,8 +175,6 @@ static synchronized void logDetails(Logger logger, String stringToLog, String pr
case TRACE:
logger.trace("{} {} {}", threadName, separator, stringToLog, throwable);
break;
default:
Copy link
Contributor

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.

Copy link
Collaborator Author

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();
Copy link
Contributor

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?

Copy link
Collaborator Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong to remove

Copy link
Collaborator Author

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.

@vlsi vlsi force-pushed the errorprone branch 2 times, most recently from d5bc20f to 453b470 Compare May 5, 2023 08:33
@vlsi vlsi merged commit af92f07 into apache:master May 5, 2023
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.

2 participants