Skip to content

Commit e87ed08

Browse files
committed
Merge pull request #19637 from nosan
* pr/19637: Fix retrieval of parent logger in PoolingDataSourceBean Closes gh-19637
2 parents b23b69f + b7e6989 commit e87ed08

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/bitronix/PoolingDataSourceBean.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,13 +107,16 @@ public XAStatefulHolder createPooledConnection(Object xaFactory, ResourceBean be
107107

108108
@Override
109109
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
110-
try {
111-
return this.getParentLogger();
112-
}
113-
catch (Exception ex) {
114-
// Work around https://jira.codehaus.org/browse/BTM-134
115-
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
110+
XADataSource dataSource = this.dataSource;
111+
if (dataSource != null) {
112+
try {
113+
return dataSource.getParentLogger();
114+
}
115+
catch (Exception ex) {
116+
// Swallow and continue
117+
}
116118
}
119+
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
117120
}
118121

119122
/**

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/bitronix/PoolingDataSourceBeanTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
1717
package org.springframework.boot.jta.bitronix;
1818

1919
import java.sql.Connection;
20+
import java.sql.SQLFeatureNotSupportedException;
21+
import java.util.logging.Logger;
2022

2123
import javax.sql.XAConnection;
2224
import javax.sql.XADataSource;
@@ -60,6 +62,28 @@ public void doesNotSetUniqueNameIfNotNull() throws Exception {
6062
assertThat(this.bean.getUniqueName()).isEqualTo("un");
6163
}
6264

65+
@Test
66+
public void shouldReturnGlobalLoggerWhenDataSourceIsAbsent() throws SQLFeatureNotSupportedException {
67+
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
68+
}
69+
70+
@Test
71+
public void shouldReturnGlobalLoggerWhenDataSourceThrowsException() throws SQLFeatureNotSupportedException {
72+
XADataSource dataSource = mock(XADataSource.class);
73+
given(dataSource.getParentLogger()).willThrow(new SQLFeatureNotSupportedException());
74+
this.bean.setDataSource(dataSource);
75+
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
76+
}
77+
78+
@Test
79+
public void shouldReturnParentLoggerFromDataSource() throws SQLFeatureNotSupportedException {
80+
Logger logger = Logger.getLogger("test");
81+
XADataSource dataSource = mock(XADataSource.class);
82+
given(dataSource.getParentLogger()).willReturn(logger);
83+
this.bean.setDataSource(dataSource);
84+
assertThat(this.bean.getParentLogger()).isSameAs(logger);
85+
}
86+
6387
@Test
6488
public void setDataSource() throws Exception {
6589
XADataSource dataSource = mock(XADataSource.class);

0 commit comments

Comments
 (0)