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

7227 : Prohibit Non Final Static Field #8558

Conversation

SandishKumarHN
Copy link
Contributor

@SandishKumarHN SandishKumarHN commented Sep 19, 2019

Fixes #7227
Prohibit Non-Final Static Field
Add annotation if required static fields @SuppressWarnings("SSBasedInspection")


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths.
  • added integration tests.
  • been tested in a test Druid cluster.

Key changed/added classes in this PR
  • MyFoo
  • OurBar
  • TheirBaz

@ccaominh
Copy link
Contributor

Please update the PR description (e.g., first line should be "Fixes #7227.", remove placeholder text, etc.).

@SandishKumarHN
Copy link
Contributor Author

@ccaominh Thanks for quick comments changed, please review now

@SandishKumarHN
Copy link
Contributor Author

@leventov can you please review this also.

@@ -55,12 +55,15 @@
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class FloatCompressionBenchmark
{
@SuppressWarnings("SSBasedInspection")
Copy link
Member

Choose a reason for hiding this comment

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

Please try to minimize these suppressions. In most *Benchmark and *Test classes static fields could be converted into instance fields.

In classes where this cannot be done, it makes sense to add @SuppressWarnings("SSBasedInspection") once on the class declaration instead of separately on every field.

In any case, each @SuppressWarnings("SSBasedInspection") should have a comment after it specifying the concrete type of Structural Search inspection being suppressed. In this PR, many of them should all look like

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block

@@ -124,8 +124,8 @@

private BenchmarkSchemaInfo schemaInfo;

private static String JS_FN = "function(str) { return 'super-' + str; }";
private static ExtractionFn JS_EXTRACTION_FN = new JavaScriptExtractionFn(JS_FN, false, JavaScriptConfig.getEnabledInstance());
private static final String JS_FN = "function(str) { return 'super-' + str; }";
Copy link
Member

Choose a reason for hiding this comment

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

Static fields should be ordered before instance fields.

@SandishKumarHN
Copy link
Contributor Author

SandishKumarHN commented Sep 22, 2019

@leventov thanks for the review, made changes based on your suggestions.

@@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

The comment is not true: field dirPath is not set in an initializer block.

@SandishKumarHN
Copy link
Contributor Author

@leventov made changes

@SandishKumarHN
Copy link
Contributor Author

@leventov "Inspections: pull requests (Druid) — TeamCity build failed" is not related to PR.

@@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an static method
Copy link
Member

Choose a reason for hiding this comment

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

If the suppression is done for a single field (dirPath), it should be on the field still. My suggestion to move the suppressions up only applied when there are more than one field in the class which needs to be suppressed.

@@ -51,7 +51,7 @@
private IncrementalIndex incIndex;
private IncrementalIndex incFloatIndex;
private IncrementalIndex incStrIndex;
private static AggregatorFactory[] aggs;
private static final AggregatorFactory[] AGGS;
Copy link
Member

Choose a reason for hiding this comment

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

Please move static fields above instance fields.

@@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an static method
Copy link
Member

Choose a reason for hiding this comment

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

If the suppression is done for a single field (dirPath), it should be on the field still.

@@ -100,6 +100,7 @@
@Fork(value = 1)
@Warmup(iterations = 10)
@Measurement(iterations = 25)
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because variable is not initilized.
Copy link
Member

Choose a reason for hiding this comment

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

If this is about ordering field, I think it could be an instance field. The order of static and instance field is also disturbed.

@@ -29,6 +29,7 @@
* introduced as part of https://github.com/apache/incubator-druid/issues/4349 and the old druid behavior
* where null values are replaced with default values e.g Null Strings are replaced with empty values.
*/
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an static method
Copy link
Member

Choose a reason for hiding this comment

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

If the suppression is done for a single field (INSTANCE), it should be on the field still.

@SandishKumarHN SandishKumarHN force-pushed the 7227-Prohibit-StaticNon-FinalFields branch from 2057858 to 06b5f70 Compare September 27, 2019 00:48
@SandishKumarHN
Copy link
Contributor Author

@leventov fixed

@SandishKumarHN SandishKumarHN force-pushed the 7227-Prohibit-StaticNon-FinalFields branch from ecce209 to 72ac63e Compare October 1, 2019 20:28
@SandishKumarHN
Copy link
Contributor Author

@leventov looks like a code inspection issue, which is not related to this PR. verified the code I don't see any duplicate code.

@leventov
Copy link
Member

There are violations in SimpleTestIndex.java

@SandishKumarHN
Copy link
Contributor Author

@leventov inspection failure from
SeekableStreamSupervisor.java (4) 175: TaskGroup() Optional<DateTime> used as type for parameter 'minimumMessageTime'

@leventov
Copy link
Member

@SandishKumarHN can you see these errors yourself here, or there is some sort of access problem that prevents your (a non-admin user) from seeing these problems?

Copy link
Member

@leventov leventov left a comment

Choose a reason for hiding this comment

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

Reviewed until SchemalessIndexTest

@@ -102,6 +102,10 @@
@Measurement(iterations = 25)
public class ScanBenchmark
{
@Param({"NONE", "DESCENDING", "ASCENDING"})
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
private static ScanQuery.Order ordering;
Copy link
Member

Choose a reason for hiding this comment

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

This field is not set in an initializer block. Please check the truthfulness of the comments that you add.

Since this is @Param, it shouldn't be static at all. Could you please prohibit static @Params by adding another structured search pattern:

@Param($Values$) static $T$ $param$;

in this PR?

@@ -50,6 +50,7 @@
* It does not take effect in all unit tests since we don't use Guice Injection.
*/
@Inject
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

Again, has nothing to do with an initializer block. In this case, it's because this field is injected it cannot be final.

@@ -35,9 +35,10 @@
/**
* Native I/O operations in order to minimize cache impact.
*/
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

Please move this suppression to FIELD.

@@ -40,6 +40,7 @@
public static final String EXCEPTION_MESSAGE_KEY = "exceptionMessage";
public static final String EXCEPTION_STACK_TRACE_KEY = "exceptionStackTrace";

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

Same problem here, the comment doesn't reflect the reality. registerEmitter() is the reason.

@@ -50,11 +50,12 @@ public static boolean isIsJava9Compatible()
}

@Inject
private static RuntimeInfo runtimeInfo = new RuntimeInfo();
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

Injection.

@@ -39,6 +39,7 @@
*/
public class MapLookupExtractionFnSerDeTest
{
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

method

@@ -35,6 +35,8 @@

public class InDimFilterSerDesrTest
{

@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

method

@@ -37,6 +37,7 @@

public class IntervalDimFilterTest
{
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
Copy link
Member

Choose a reason for hiding this comment

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

method

@@ -36,6 +36,7 @@

public class ScanResultValueTimestampComparatorTest
{
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block
private static QuerySegmentSpec intervalSpec;
Copy link
Member

Choose a reason for hiding this comment

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

setup() can be inlined

@@ -64,9 +64,10 @@

/**
*/
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an static method
Copy link
Member

Choose a reason for hiding this comment

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

mergedIndex doesn't need to be static. It seems to be that index doesn't need to be static, too. getIncrementalIndex() and makeIncrementalIndex() should become non-static, too.

@stale
Copy link

stale bot commented Dec 15, 2019

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@druid.apache.org list. Thank you for your contributions.

@stale stale bot added the stale label Dec 15, 2019
@stale
Copy link

stale bot commented Jan 12, 2020

This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale bot closed this Jan 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prohibit static, non-final fields
3 participants