Allocate objects only when it's necessary

Closes gh-23036
This commit is contained in:
Сергей Цыпанов 2019-05-27 12:14:25 +03:00 committed by Sam Brannen
parent 6f2f5bb8c1
commit 6964ed33bf
4 changed files with 4 additions and 4 deletions

View File

@ -484,12 +484,12 @@ public abstract class AbstractJdbcInsert {
//Get the key //Get the key
Statement keyStmt = null; Statement keyStmt = null;
ResultSet rs = null; ResultSet rs = null;
Map<String, Object> keys = new HashMap<>(2);
try { try {
keyStmt = con.createStatement(); keyStmt = con.createStatement();
rs = keyStmt.executeQuery(keyQuery); rs = keyStmt.executeQuery(keyQuery);
if (rs.next()) { if (rs.next()) {
long key = rs.getLong(1); long key = rs.getLong(1);
Map<String, Object> keys = new HashMap<>(2);
keys.put(getGeneratedKeyNames()[0], key); keys.put(getGeneratedKeyNames()[0], key);
keyHolder.getKeyList().add(keys); keyHolder.getKeyList().add(keys);
} }

View File

@ -245,9 +245,9 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
for (String suffix : suffixes) { for (String suffix : suffixes) {
Assert.hasText(suffix, "Resource suffix must not be empty"); Assert.hasText(suffix, "Resource suffix must not be empty");
String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix; String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix;
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
ClassPathResource classPathResource = new ClassPathResource(resourcePath); ClassPathResource classPathResource = new ClassPathResource(resourcePath);
if (classPathResource.exists()) { if (classPathResource.exists()) {
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info(String.format("Detected default resource location \"%s\" for test class [%s]", logger.info(String.format("Detected default resource location \"%s\" for test class [%s]",
prefixedResourcePath, clazz.getName())); prefixedResourcePath, clazz.getName()));

View File

@ -156,10 +156,10 @@ class TestPropertySourceAttributes {
*/ */
private static String detectDefaultPropertiesFile(Class<?> testClass) { private static String detectDefaultPropertiesFile(Class<?> testClass) {
String resourcePath = ClassUtils.convertClassNameToResourcePath(testClass.getName()) + ".properties"; String resourcePath = ClassUtils.convertClassNameToResourcePath(testClass.getName()) + ".properties";
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
ClassPathResource classPathResource = new ClassPathResource(resourcePath); ClassPathResource classPathResource = new ClassPathResource(resourcePath);
if (classPathResource.exists()) { if (classPathResource.exists()) {
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info(String.format("Detected default properties file \"%s\" for test class [%s]", logger.info(String.format("Detected default properties file \"%s\" for test class [%s]",
prefixedResourcePath, testClass.getName())); prefixedResourcePath, testClass.getName()));

View File

@ -637,11 +637,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
private void resumeAfterBeginException( private void resumeAfterBeginException(
Object transaction, @Nullable SuspendedResourcesHolder suspendedResources, Throwable beginEx) { Object transaction, @Nullable SuspendedResourcesHolder suspendedResources, Throwable beginEx) {
String exMessage = "Inner transaction begin exception overridden by outer transaction resume exception";
try { try {
resume(transaction, suspendedResources); resume(transaction, suspendedResources);
} }
catch (RuntimeException | Error resumeEx) { catch (RuntimeException | Error resumeEx) {
String exMessage = "Inner transaction begin exception overridden by outer transaction resume exception";
logger.error(exMessage, beginEx); logger.error(exMessage, beginEx);
throw resumeEx; throw resumeEx;
} }