Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1511

DynamicThresholdFilter filters incorrectly when params are passed as individual arguments instead of varargs

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.2
    • Fix Version/s: 2.7
    • Component/s: None
    • Labels:
      None

      Description

      The below test should summarize the issue.

      package org.apache.logging.log4j.core.filter;
      
      import static org.junit.Assert.assertSame;
      import static org.junit.Assert.assertTrue;
      
      import org.apache.logging.log4j.Level;
      import org.apache.logging.log4j.ThreadContext;
      import org.apache.logging.log4j.core.Filter;
      import org.apache.logging.log4j.core.LoggerContext;
      import org.apache.logging.log4j.core.util.KeyValuePair;
      import org.apache.logging.log4j.status.StatusLogger;
      import org.junit.After;
      import org.junit.Test;
      
      /**
       *
       */
      public class DynamicThresholdFilterTest {
      
          @After
          public void cleanup() {
              final LoggerContext ctx = LoggerContext.getContext(false);
              ctx.reconfigure();
              StatusLogger.getLogger().reset();
          }
      
          @Test
          public void testFilter() {
              ThreadContext.put("userid", "testuser");
              ThreadContext.put("organization", "apache");
              final KeyValuePair[] pairs = new KeyValuePair[] {
                      new KeyValuePair("testuser", "DEBUG"),
                      new KeyValuePair("JohnDoe", "warn") };
              final DynamicThresholdFilter filter = DynamicThresholdFilter.createFilter("userid", pairs, Level.ERROR, Filter.Result.ACCEPT, Filter.Result.NEUTRAL);
              filter.start();
              assertTrue(filter.isStarted());
              Object [] replacements = {"one", "two", "three"};
              assertSame(Filter.Result.ACCEPT, filter.filter(null, Level.DEBUG, null, "some test message", replacements)); // Works
              assertSame(Filter.Result.ACCEPT, filter.filter(null, Level.DEBUG, null, "some test message", "one", "two", "three")); // Doesn't work but it should
              ThreadContext.clearMap();
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                srikanth.surukuntu@gmail.com Srikanth
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: