You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2020/02/03 23:42:36 UTC

[logging-log4j2] branch release-2.x updated: [LOG4J2-2770] CronExpression.getBeforeTime() would sometimes return incorrect result.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new f2d81e9  [LOG4J2-2770] CronExpression.getBeforeTime() would sometimes return incorrect result.
f2d81e9 is described below

commit f2d81e9f3a3900f2a0f85b906cfe772915ce1147
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 3 18:42:31 2020 -0500

    [LOG4J2-2770] CronExpression.getBeforeTime() would sometimes return
    incorrect result.
---
 .../log4j/core/config/ConfigurationSource.java     | 12 ++++----
 .../log4j/core/config/ConfigurationSourceTest.java | 33 ++++++++++++++++++++++
 src/changes/changes.xml                            |  3 ++
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
index 3630c41..431d136 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
@@ -43,16 +43,18 @@ import org.apache.logging.log4j.util.LoaderUtil;
  */
 public class ConfigurationSource {
 
+    /** Empty byte array singleton. */
+    private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
     /**
      * ConfigurationSource to use with Configurations that do not require a "real" configuration source.
      */
-    public static final ConfigurationSource NULL_SOURCE = new ConfigurationSource(new byte[0], null, 0);
+    public static final ConfigurationSource NULL_SOURCE = new ConfigurationSource(EMPTY_BYTE_ARRAY, null, 0);
+
     /**
      * ConfigurationSource to use with {@link org.apache.logging.log4j.core.config.composite.CompositeConfiguration}.
      */
-    public static final ConfigurationSource COMPOSITE_SOURCE = new ConfigurationSource(new byte[0], null, 0);
-    private static final String HTTPS = "https";
-    private static final String HTTP = "http";
+    public static final ConfigurationSource COMPOSITE_SOURCE = new ConfigurationSource(EMPTY_BYTE_ARRAY, null, 0);
 
     private final File file;
     private final URL url;
@@ -141,7 +143,7 @@ public class ConfigurationSource {
     }
 
     private ConfigurationSource(final byte[] data, final URL url, long lastModified) {
-        Objects.requireNonNull(data, "data is null");
+        this.data = Objects.requireNonNull(data, "data is null");
         this.stream = new ByteArrayInputStream(data);
         this.file = null;
         this.url = url;
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationSourceTest.java
new file mode 100644
index 0000000..5ca42f2
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationSourceTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.config;
+
+import java.io.ByteArrayInputStream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ConfigurationSourceTest {
+
+    @Test
+    public void testJira_LOG4J2_2770_byteArray() throws Exception {
+        ConfigurationSource configurationSource = new ConfigurationSource(
+                new ByteArrayInputStream(new byte[] { 'a', 'b' }));
+        Assert.assertNotNull(configurationSource.resetInputStream());
+    }
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 53d98a6..25d979c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,9 @@
       <action issue="LOG4J2-2763" dev="ggregory" type="update">
         Update dependencies.
       </action>
+      <action issue="LOG4J2-2770" dev="ggregory" type="fix" due-to="Bill Kuker">
+        CronExpression.getBeforeTime() would sometimes return incorrect result.
+      </action>
     </release>
     <release version="2.13.0" date="2019-12-11" description="GA Release 2.13.0">
       <action issue="LOG4J2-2058" dev="rgoers" type="fix">