-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
7227 : Prohibit Non Final Static Field #8558
Conversation
Please update the PR description (e.g., first line should be "Fixes #7227.", remove placeholder text, etc.). |
@ccaominh Thanks for quick comments changed, please review now |
…ibit-StaticNon-FinalFields
@leventov can you please review this also. |
@@ -55,12 +55,15 @@ | |||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |||
public class FloatCompressionBenchmark | |||
{ | |||
@SuppressWarnings("SSBasedInspection") |
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.
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; }"; |
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.
Static fields should be ordered before instance fields.
@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 |
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 comment is not true: field dirPath
is not set in an initializer block.
@leventov made changes |
@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 |
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.
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; |
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.
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 |
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.
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. |
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.
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 |
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.
If the suppression is done for a single field (INSTANCE
), it should be on the field still.
2057858
to
06b5f70
Compare
@leventov fixed |
ecce209
to
72ac63e
Compare
@leventov looks like a code inspection issue, which is not related to this PR. verified the code I don't see any duplicate code. |
There are violations in |
@leventov inspection failure from |
@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? |
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.
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; |
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 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 |
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.
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 |
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.
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 |
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.
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 |
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.
Injection.
@@ -39,6 +39,7 @@ | |||
*/ | |||
public class MapLookupExtractionFnSerDeTest | |||
{ | |||
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block |
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.
method
@@ -35,6 +35,8 @@ | |||
|
|||
public class InDimFilterSerDesrTest | |||
{ | |||
|
|||
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block |
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.
method
@@ -37,6 +37,7 @@ | |||
|
|||
public class IntervalDimFilterTest | |||
{ | |||
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an initializer block |
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.
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; |
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.
setup() can be inlined
@@ -64,9 +64,10 @@ | |||
|
|||
/** | |||
*/ | |||
@SuppressWarnings("SSBasedInspection") // static field(s) cannot be final because set in an static method |
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.
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.
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. |
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. |
Fixes #7227
Prohibit Non-Final Static Field
Add annotation if required static fields @SuppressWarnings("SSBasedInspection")
This PR has:
Key changed/added classes in this PR
MyFoo
OurBar
TheirBaz