Skip to content

Commit

Permalink
Fix StackOverflowError in PoolingDataSourceBean
Browse files Browse the repository at this point in the history
  • Loading branch information
nosan committed Jan 11, 2020
1 parent b97b0c1 commit d9c0c45
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,14 +106,17 @@ public XAStatefulHolder createPooledConnection(Object xaFactory, ResourceBean be
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
try {
return this.getParentLogger();
}
catch (Exception ex) {
// Work around https://jira.codehaus.org/browse/BTM-134
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
public Logger getParentLogger() {
XADataSource dataSource = this.dataSource;
if (dataSource != null) {
try {
return dataSource.getParentLogger();
}
catch (Exception ex) {
// Swallow and continue
}
}
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
package org.springframework.boot.jta.bitronix;

import java.sql.Connection;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import javax.sql.XAConnection;
import javax.sql.XADataSource;
Expand Down Expand Up @@ -60,6 +62,28 @@ void doesNotSetUniqueNameIfNotNull() throws Exception {
assertThat(this.bean.getUniqueName()).isEqualTo("un");
}

@Test
void shouldReturnGlobalLoggerWhenDataSourceIsAbsent() {
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
}

@Test
void shouldReturnGlobalLoggerWhenDataSourceThrowsException() throws SQLFeatureNotSupportedException {
XADataSource dataSource = mock(XADataSource.class);
given(dataSource.getParentLogger()).willThrow(new SQLFeatureNotSupportedException());
this.bean.setDataSource(dataSource);
assertThat(this.bean.getParentLogger()).isSameAs(Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
}

@Test
void shouldReturnParentLoggerFromDataSource() throws SQLFeatureNotSupportedException {
Logger logger = Logger.getLogger("test");
XADataSource dataSource = mock(XADataSource.class);
given(dataSource.getParentLogger()).willReturn(logger);
this.bean.setDataSource(dataSource);
assertThat(this.bean.getParentLogger()).isSameAs(logger);
}

@Test
void setDataSource() throws Exception {
XADataSource dataSource = mock(XADataSource.class);
Expand Down

0 comments on commit d9c0c45

Please sign in to comment.