diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
index 6483bb0b4e..ab70bf9b38 100644
--- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
+++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
@@ -160,7 +160,7 @@ public class EnableAsyncTests {
Object bean = ctx.getBean(CustomAsyncBean.class);
assertTrue(AopUtils.isAopProxy(bean));
boolean isAsyncAdvised = false;
- for (Advisor advisor : ((Advised)bean).getAdvisors()) {
+ for (Advisor advisor : ((Advised) bean).getAdvisors()) {
if (advisor instanceof AsyncAnnotationAdvisor) {
isAsyncAdvised = true;
break;
@@ -364,7 +364,8 @@ public class EnableAsyncTests {
@EnableAsync
static class AsyncConfigWithMockito {
- @Bean @Lazy
+ @Bean
+ @Lazy
public AsyncBean asyncBean() {
return Mockito.mock(AsyncBean.class);
}
diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java
index aef52f3801..da5a3af0ed 100644
--- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java
+++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -23,28 +23,29 @@ import javax.naming.NamingException;
import org.springframework.jndi.JndiTemplate;
/**
- * Simple extension of the JndiTemplate class that always returns
- * a given object. Very useful for testing. Effectively a mock object.
+ * Simple extension of the JndiTemplate class that always returns a given object.
+ *
+ *
Very useful for testing. Effectively a mock object.
*
* @author Rod Johnson
* @author Juergen Hoeller
*/
public class ExpectedLookupTemplate extends JndiTemplate {
- private final Map jndiObjects = new ConcurrentHashMap<>();
+ private final Map jndiObjects = new ConcurrentHashMap<>(16);
/**
- * Construct a new JndiTemplate that will always return given objects
- * for given names. To be populated through {@code addObject} calls.
+ * Construct a new JndiTemplate that will always return given objects for
+ * given names. To be populated through {@code addObject} calls.
* @see #addObject(String, Object)
*/
public ExpectedLookupTemplate() {
}
/**
- * Construct a new JndiTemplate that will always return the
- * given object, but honour only requests for the given name.
+ * Construct a new JndiTemplate that will always return the given object,
+ * but honour only requests for the given name.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
@@ -54,8 +55,7 @@ public class ExpectedLookupTemplate extends JndiTemplate {
/**
- * Add the given object to the list of JNDI objects that this
- * template will expose.
+ * Add the given object to the list of JNDI objects that this template will expose.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
@@ -63,11 +63,10 @@ public class ExpectedLookupTemplate extends JndiTemplate {
this.jndiObjects.put(name, object);
}
-
/**
- * If the name is the expected name specified in the constructor,
- * return the object provided in the constructor. If the name is
- * unexpected, a respective NamingException gets thrown.
+ * If the name is the expected name specified in the constructor, return the
+ * object provided in the constructor. If the name is unexpected, a
+ * respective NamingException gets thrown.
*/
@Override
public Object lookup(String name) throws NamingException {
diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java
index c4ba15c217..ef0d414b59 100644
--- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java
+++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -33,6 +33,7 @@ import javax.naming.OperationNotSupportedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -80,7 +81,9 @@ public class SimpleNamingContext implements Context {
* Create a new naming context with the given naming root,
* the given name/object map, and the JNDI environment entries.
*/
- public SimpleNamingContext(String root, Hashtable boundObjects, Hashtable env) {
+ public SimpleNamingContext(
+ String root, Hashtable boundObjects, @Nullable Hashtable env) {
+
this.root = root;
this.boundObjects = boundObjects;
if (env != null) {
@@ -206,6 +209,7 @@ public class SimpleNamingContext implements Context {
}
@Override
+ @Nullable
public Object addToEnvironment(String propName, Object propVal) {
return this.environment.put(propName, propVal);
}
@@ -293,7 +297,7 @@ public class SimpleNamingContext implements Context {
}
- private static abstract class AbstractNamingEnumeration implements NamingEnumeration {
+ private abstract static class AbstractNamingEnumeration implements NamingEnumeration {
private Iterator iterator;
@@ -353,7 +357,7 @@ public class SimpleNamingContext implements Context {
}
- private static class NameClassPairEnumeration extends AbstractNamingEnumeration {
+ private static final class NameClassPairEnumeration extends AbstractNamingEnumeration {
private NameClassPairEnumeration(SimpleNamingContext context, String root) throws NamingException {
super(context, root);
@@ -366,7 +370,7 @@ public class SimpleNamingContext implements Context {
}
- private static class BindingEnumeration extends AbstractNamingEnumeration {
+ private static final class BindingEnumeration extends AbstractNamingEnumeration {
private BindingEnumeration(SimpleNamingContext context, String root) throws NamingException {
super(context, root);
diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
index 56fc6e802b..6c3a3d7780 100644
--- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
+++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -26,7 +26,10 @@ import javax.naming.spi.NamingManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
/**
* Simple implementation of a JNDI naming context builder.
@@ -42,7 +45,7 @@ import org.springframework.util.ClassUtils;
*
*
{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
*
{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
- *
Apache's Jakarta Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
+ *
Apache's Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
*
*
*
Typical usage in bootstrap code:
@@ -80,7 +83,8 @@ import org.springframework.util.ClassUtils;
*/
public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder {
- /** An instance of this class bound to JNDI */
+ /** An instance of this class bound to JNDI. */
+ @Nullable
private static volatile SimpleNamingContextBuilder activated;
private static boolean initialized = false;
@@ -93,13 +97,14 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
* @return the current SimpleNamingContextBuilder instance,
* or {@code null} if none
*/
+ @Nullable
public static SimpleNamingContextBuilder getCurrentContextBuilder() {
return activated;
}
/**
* If no SimpleNamingContextBuilder is already configuring JNDI,
- * create and activate one. Otherwise take the existing activate
+ * create and activate one. Otherwise take the existing activated
* SimpleNamingContextBuilder, clear it and return it.
*