This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 7f43a4e [LOG4J2-2612] NullPointerException at
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:803).
7f43a4e is described below
commit 7f43a4e2789253a8acbb82a874dd4c3efe225eb1
Author: Gary Gregory <[email protected]>
AuthorDate: Wed May 29 21:08:13 2019 -0400
[LOG4J2-2612] NullPointerException at
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:803).
---
.../log4j/jdbc/appender/JdbcDatabaseManager.java | 44 +++++++++++++++++-----
src/changes/changes.xml | 11 +++++-
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git
a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/JdbcDatabaseManager.java
b/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/JdbcDatabaseManager.java
index 7f55eed..6e91f29 100644
---
a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/JdbcDatabaseManager.java
+++
b/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/JdbcDatabaseManager.java
@@ -25,6 +25,7 @@ import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
@@ -412,13 +413,13 @@ public final class JdbcDatabaseManager extends
AbstractDatabaseManager {
private void checkConnection() {
boolean connClosed = true;
try {
- connClosed = this.connection == null || this.connection.isClosed();
+ connClosed = isClosed(this.connection);
} catch (final SQLException e) {
// Be quiet
}
boolean stmtClosed = true;
try {
- stmtClosed = this.statement == null || this.statement.isClosed();
+ stmtClosed = isClosed(this.statement);
} catch (final SQLException e) {
// Be quiet
}
@@ -441,28 +442,28 @@ public final class JdbcDatabaseManager extends
AbstractDatabaseManager {
}
protected void closeResources(final boolean logExceptions) {
+ final PreparedStatement tempPreparedStatement = this.statement;
+ this.statement = null;
try {
// Closing a statement returns it to the pool when using Apache
Commons DBCP.
// Closing an already closed statement has no effect.
- Closer.close(this.statement);
+ Closer.close(tempPreparedStatement);
} catch (final Exception e) {
if (logExceptions) {
logWarn("Failed to close SQL statement logging event or
flushing buffer", e);
}
- } finally {
- this.statement = null;
}
+ final Connection tempConnection = this.connection;
+ this.connection = null;
try {
// Closing a connection returns it to the pool when using Apache
Commons DBCP.
// Closing an already closed connection has no effect.
- Closer.close(this.connection);
+ Closer.close(tempConnection);
} catch (final Exception e) {
if (logExceptions) {
logWarn("Failed to close database connection logging event or
flushing buffer", e);
}
- } finally {
- this.connection = null;
}
}
@@ -588,6 +589,28 @@ public final class JdbcDatabaseManager extends
AbstractDatabaseManager {
}
}
+ /**
+ * Checks if a statement is closed. A null statement is considered closed.
+ *
+ * @param statement The statement to check.
+ * @return true if a statement is closed, false if null.
+ * @throws SQLException if a database access error occurs
+ */
+ private boolean isClosed(final Statement statement) throws SQLException {
+ return statement == null || statement.isClosed();
+ }
+
+ /**
+ * Checks if a connection is closed. A null connection is considered
closed.
+ *
+ * @param connection The connection to check.
+ * @return true if a connection is closed, false if null.
+ * @throws SQLException if a database access error occurs
+ */
+ private boolean isClosed(final Connection connection) throws SQLException {
+ return connection == null || connection.isClosed();
+ }
+
private void reconnectOn(final Exception exception) {
if (!factoryData.retry) {
throw new AppenderLoggingException("Cannot connect and prepare",
exception);
@@ -744,7 +767,10 @@ public final class JdbcDatabaseManager extends
AbstractDatabaseManager {
} finally {
// Release ASAP
try {
- statement.clearParameters();
+ // statement can be null when a AppenderLoggingException is
thrown at the start of this method
+ if (statement != null) {
+ statement.clearParameters();
+ }
} catch (final SQLException e) {
// Ignore
}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 53c28d4..e4cbc7e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -388,6 +388,9 @@
<action issue="LOG4J2-2598" dev="ggregory" type="fix" due-to="Gary
Gregory">
java.lang.StackOverflowError at
org.apache.logging.log4j.junit.AbstractExternalFileCleaner.println(AbstractExternalFileCleaner.java:169).
</action>
+ <action issue="LOG4J2-2612" dev="ggregory" type="fix">
+ NullPointerException at
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:803).
+ </action>
</release>
<release version="2.12.0" date="2019-MM-DD" description="GA Release
2.12.0">
<action issue="LOG4J2-2561" dev="rgoers" type="fix" due-to="Ulrich
Enslin">
@@ -414,9 +417,12 @@
<action dev="ggregory" type="update" due-to="Gary Gregory">
Update tests from H2 1.4.197 to 1.4.199.
</action>
- <action issue="LOG4J2-2570" dev="ggregory" type="fix" due-to="Gary
Gregory">
+ <action issue="LOG4J2-2570" dev="ggregory" type="update" due-to="Gary
Gregory">
Update Jackson from 2.9.7 to 2.9.8.
</action>
+ <action issue="LOG4J2-2574" dev="ggregory" type="update" due-to="Gary
Gregory">
+ Update MongoDB 3 module driver from 3.9.0 to 3.10.1.
+ </action>
<action issue="LOG4J2-2592" dev="ggregory" type="fix" due-to="Dávid
Kaya, Gary Gregory">
StackOverflowException when server not reachable with SocketAppender.
</action>
@@ -436,6 +442,9 @@
<action issue="LOG4J2-2611" dev="ckozak" type="add">
AsyncQueueFullPolicy configuration short values "Default" and
"Discard" are case insensitive to avoid confusion.
</action>
+ <action issue="LOG4J2-2612" dev="ggregory" type="fix">
+ NullPointerException at
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:803).
+ </action>
</release>
<release version="2.11.2" date="2018-MM-DD" description="GA Release
2.11.2">
<action issue="LOG4J2-2500" dev="rgoers" type="fix">