You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2020/02/03 22:44:38 UTC

[GitHub] [logging-log4j2] turbanoff opened a new pull request #338: use 'final' modifier for fields where possible

turbanoff opened a new pull request #338: use 'final' modifier for fields where possible
URL: https://github.com/apache/logging-log4j2/pull/338
 
 
   Also removed 2 unused fields which my IDEA highlights as possible `final`, but fields were unused (leftovers after refactoring):
   1. `DefaultLogBuilder.EMPTY_MESSAGE`
   2. `DirectWriteRolloverStrategy.usePrevTime`
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on issue #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff commented on issue #338: use 'final' modifier for fields where possible
URL: https://github.com/apache/logging-log4j2/pull/338#issuecomment-581656719
 
 
   I didn't touch fields in samples, tests and perf modules.
   Field `org.apache.logging.log4j.core.layout.AbstractStringLayout#charset` looks strange. Looks like it should be initialized in `readObject` method, but it was removed here - https://github.com/apache/logging-log4j2/commit/afd417ce965fd6100134ac775aef1be98a927250
   See https://github.com/apache/logging-log4j2/commit/afd417ce965fd6100134ac775aef1be98a927250#diff-1c90b17f7481c4e5ae5a134261a36209
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r377943921
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
 ##########
 @@ -44,7 +44,7 @@
     private static final int HASHVAL = 31;
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   fixed

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
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_r374413039
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
 ##########
 @@ -69,10 +69,10 @@
     private static final int HASHVAL = 31;
 
     // storing JDK classes in ThreadLocals does not cause memory leaks in web apps, so this is okay
-    private static ThreadLocal<StringBuilder> threadLocalStringBuilder = new ThreadLocal<>();
+    private static final ThreadLocal<StringBuilder> threadLocalStringBuilder = new ThreadLocal<>();
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   I don't believe transient fields should be marked final.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r376814654
 
 

 ##########
 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:
   Just couple examples to show, that having `final transient` it's ok:
   https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/time/ZoneRegion.java#L104
   https://github.com/OpenGamma/Strata/blob/master/modules/collect/src/main/java/com/opengamma/strata/collect/array/DoubleMatrix.java#L66
   https://github.com/google/guava/blob/master/guava/src/com/google/common/reflect/TypeToken.java#L701
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r377943882
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
 ##########
 @@ -37,7 +37,7 @@
     private static final Pattern MSG_PATTERN = Pattern.compile(FORMAT_SPECIFIER);
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   fixed

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
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_r374412481
 
 

 ##########
 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:
   I don't believe it is wise for transient fields to be marked final.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
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_r374413266
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
 ##########
 @@ -44,7 +44,7 @@
     private static final int HASHVAL = 31;
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   I don't believe transient fields should be marked final.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r377943901
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
 ##########
 @@ -69,10 +69,10 @@
     private static final int HASHVAL = 31;
 
     // storing JDK classes in ThreadLocals does not cause memory leaks in web apps, so this is okay
-    private static ThreadLocal<StringBuilder> threadLocalStringBuilder = new ThreadLocal<>();
+    private static final ThreadLocal<StringBuilder> threadLocalStringBuilder = new ThreadLocal<>();
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   fixed

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r376771316
 
 

 ##########
 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:
   >It is quite possible that the objects can be recreated during deserialization from the data that is present.
   
   But there is no such code. It means they are not recreated. I someone in future will deserialization code - he can also remove `final` modifier.
   
   Moreover if classes `FormattedMessage`, `StringFormattedMessage` and `ParameterizedMessage`: code is already ready to have this fields `final` and `null`. Such fields are not serialized and not read from ObjectOutputStream.
   
   If you insist - I will remove final

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r376771316
 
 

 ##########
 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:
   >It is quite possible that the objects can be recreated during deserialization from the data that is present.
   
   But there is no such code. It means they are not recreated. I someone in future will write deserialization code - he can also remove `final` modifier.
   
   Moreover in classes `FormattedMessage`, `StringFormattedMessage` and `ParameterizedMessage`: code is already ready to have this fields `final` and `null`. Such fields are not serialized and not read from ObjectOutputStream.
   
   If you insist - I will remove final

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r376738565
 
 

 ##########
 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:
   Can you please elaborate? I don't see reasons to not do them `final`.
   Behavior of this field will be same - after deserialization field will 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers merged pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
rgoers merged pull request #338: use 'final' modifier for fields where possible
URL: https://github.com/apache/logging-log4j2/pull/338
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] rgoers commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
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_r374412811
 
 

 ##########
 File path: log4j-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
 ##########
 @@ -37,7 +37,7 @@
     private static final Pattern MSG_PATTERN = Pattern.compile(FORMAT_SPECIFIER);
 
     private String messagePattern;
-    private transient Object[] argArray;
+    private final transient Object[] argArray;
 
 Review comment:
   I don't believe transient fields should be marked final.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] remkop commented on issue #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
remkop commented on issue #338: use 'final' modifier for fields where possible
URL: https://github.com/apache/logging-log4j2/pull/338#issuecomment-583784498
 
 
   As for why transient fields should not be `final`: https://stackoverflow.com/questions/2968876/final-transient-fields-and-serialization

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [logging-log4j2] turbanoff commented on a change in pull request #338: use 'final' modifier for fields where possible

Posted by GitBox <gi...@apache.org>.
turbanoff 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_r376738565
 
 

 ##########
 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:
   Can you please elaborate? I don't see reasons to not do them `final`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services