rgoers commented on a change in pull request #338: use 'final' modifier for
fields where possible
URL: https://github.com/apache/logging-log4j2/pull/338#discussion_r376760048
##########
File path:
log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
##########
@@ -29,8 +29,8 @@
static final long serialVersionUID = -4748765566864322735L;
- private transient Throwable throwable;
- private Method toStringList;
+ private final transient Throwable throwable;
Review comment:
final fields are either initialized in the constructor or as assignments on
their declaration. Many fields that are declared transient because the values
assigned to them are not serializable, not because it is OK for them to be null
when the object is reinstantiated via deserialization. It is quite possible
that the objects can be recreated during deserialization from the data that is
present. But if the fields are marked final those recreated objects cannot be
stored in the appropriate fields without using reflection.
In summary, marking a field as transient simply means it cannot be
automatically serialized and deserialized. In no way does it imply that is
expected to always be null.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services