[ 
https://issues.apache.org/jira/browse/LOG4J2-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16827020#comment-16827020
 ] 

Gary Gregory commented on LOG4J2-2596:
--------------------------------------

Hi [~Hecoz],

Log4j 1 has reached EOL, please update to Log4j 2.

Gary

> AppenderSkeleton may introduce NullPointerException
> ---------------------------------------------------
>
>                 Key: LOG4J2-2596
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2596
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>            Reporter: Hiram
>            Priority: Critical
>              Labels: easyfix
>
> Hello, I am a software tester. I found this problem in all versions of log4j. 
> AppenderSkeleton may cause a NullPointerException error.
>  
> //Error code fragment
> public boolean isAsSevereAsThreshold(Priority priority){    
>     return this.threshold == null || 
> priority.isGreaterOrEqual(this.threshold);
> }
> public void setThreshold(Priority threshold){    
>     this.threshold = threshold;
> }
>  
> In the AppenderSkeleton class, if the isAsSevereAsThreshold() method and 
> setThreshold are executed simultaneously by two threads, 
> isAsSevereAsThreshold method checks that this.threshold is not null, another 
> thread calls the setThreshold method and sets the threshold to null. When the 
> thread switches back to the isAsSevereAsThreshold method to continue 
> execution, it will trigger a NullPointerException.
>  
> There are many classes that extends AppenderSkeleton, which can cause this 
> error if they are interleaved by different threads.
> This is an atomic violation.
> This error can be triggered by the following test:
>  
> public static void main(String[] args) throws Exception {
>     AppenderSkeleton app = new NullAppender();
>     Thread t1 = new Thread(new Runnable() {
>         @Override
>         public void run() {
>             for (int i = 0; i < 90000;i++){                     
>                 app.setThreshold(Priority.DEBUG);                             
>                app.isAsSevereAsThreshold(Priority.DEBUG);            
>            }
>         }
>     });
>     Thread t2 = new Thread(new Runnable() {
>         @Override
>         public void run() {
>             for (int i = 0; i < 90000;i++){ 
>                 app.setThreshold(null);
>             }
>         }
>     });
>     t1.start();
>     t2.start();
>     t1.join();
>     t2.join();
> }
>  
> Error message:
> Exception in thread "Thread-0" java.lang.NullPointerException
>     at org.apache.log4j.Priority.isGreaterOrEqual(Priority.java:123)
>     at 
> org.apache.log4j.AppenderSkeleton.isAsSevereAsThreshold(AppenderSkeleton.java:219)
>     at test.TestSequence$1.run(TestSequence.java:19)
>     at java.lang.Thread.run(Thread.java:748)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to