-
Notifications
You must be signed in to change notification settings - Fork 125
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
Issue a warning when final field is overwritten #414 #420
Conversation
Turns out we have more than 10 tests which do exactly that - overwrite final fields. What should we do - should we update them all? |
IMO yes we should - our code should set a good example |
+1. Yes, please fix any tests which overwrite final fields. |
db92898
to
828b5e4
Compare
De-finalize marshallable fields to remove warnings closes #414
Kudos, SonarCloud Quality Gate passed! |
@@ -641,6 +650,14 @@ protected void readValue(Object o, Object defaults, ValueIn read, boolean overwr | |||
} | |||
} | |||
|
|||
protected void triggerFinalWarning() { |
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.
Suggest assertNonFinal()
. In this version, there will be a warning but in later, an Exception would be thrown.
final List<Integer> numbers = new ArrayList<>(); | ||
final Map<String, String> map1 = new LinkedHashMap<>(); | ||
final Map<String, Double> map2 = new LinkedHashMap<>(); | ||
Set<String> words = new LinkedHashSet<>(); |
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.
Can't mutable objects be final?
It's important to recognise how Java Serialization does this currently, as we can't change that behaviour. Java Serialization doesn't produce a warning when setting final fields, nor does it expect you to make a field that can be set non-final |
#414