-
Notifications
You must be signed in to change notification settings - Fork 742
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 FieldCanBeStatic checker #930
Conversation
@@ -0,0 +1,62 @@ | |||
/* | |||
* Copyright 2017 The Error Prone Authors. |
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.
s/2017/2018 ?
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.
Done.
@BugPattern( | ||
name = "FieldCanBeStatic", | ||
category = JDK, | ||
summary = "A final field with an immutable type can be static.", |
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 wonder if this summary would explain its corresponding bug checker's purpose better with a description like the following?
A final field initialized at compile-time with an instance of an immutable type can be static.
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.
Done.
" private final Object finalMutable = new Object();", | ||
" private final int nonLiteral = new java.util.Random().nextInt();", | ||
"}") | ||
.doTest(); |
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.
@gaul I think it's worth adding another negative case where the final
fields are initialized in a constructor, like one would with a POJO. So something like this:
class Person {
final String name;
final int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
}
WDYT?
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.
Done.
8f04af8
to
9a6b056
Compare
Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Found via a proposed error-prone pull request: google/error-prone#930 MozReview-Commit-ID: CMj6vqFeCdI --HG-- extra : rebase_source : 43e91b3d8ff4bd8171ac25bd0b333d09645687a6
9a6b056
to
582e14c
Compare
582e14c
to
c6b95cc
Compare
Any chance this merge conflict can be resolved? |
This finds final fields which are initialized with a literal. Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time.
c6b95cc
to
52b1ca7
Compare
Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Found via a proposed error-prone pull request: google/error-prone#930 MozReview-Commit-ID: CMj6vqFeCdI UltraBlame original commit: e0a19b7fc6f6a44a990dacf210e871eda7eeddce
Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Found via a proposed error-prone pull request: google/error-prone#930 MozReview-Commit-ID: CMj6vqFeCdI UltraBlame original commit: e0a19b7fc6f6a44a990dacf210e871eda7eeddce
Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Found via a proposed error-prone pull request: google/error-prone#930 MozReview-Commit-ID: CMj6vqFeCdI UltraBlame original commit: e0a19b7fc6f6a44a990dacf210e871eda7eeddce
This finds final fields which are initialized with a literal. Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Fixes #930 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=312137814
This finds final fields which are initialized with a literal. Adding static reduces memory overhead from per-instance to per-class and allows initialization at compile-time instead of run-time. Fixes #930 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=312137814
This finds final fields which are initialized with a literal. Adding
static reduces memory overhead from per-instance to per-class and
allows initialization at compile-time instead of run-time.