Browse Source

Polishing

pull/1916/head
Juergen Hoeller 6 years ago
parent
commit
f5dd4d2c02
  1. 3
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  2. 14
      spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java
  3. 10
      spring-core/src/main/java/org/springframework/core/ResolvableType.java

3
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -31,7 +31,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -156,7 +155,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
private final NamedThreadLocal<String> currentlyCreatedBean = new NamedThreadLocal<>("Currently created bean"); private final NamedThreadLocal<String> currentlyCreatedBean = new NamedThreadLocal<>("Currently created bean");
/** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */ /** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */
private final Map<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16); private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16);
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */ /** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache = private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =

14
spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,7 +47,7 @@ import static org.junit.Assert.*;
/** /**
* Unit tests for {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor} * Unit tests for {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor}
* processing the JSR-303 {@link javax.inject.Inject} annotation. * processing the JSR-330 {@link javax.inject.Inject} annotation.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.0 * @since 3.0
@ -550,11 +550,9 @@ public class InjectAnnotationBeanPostProcessorTests {
} }
/** /**
* Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean} can be autowired via * Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean}
* {@link org.springframework.beans.factory.annotation.Autowired @Inject}, specifically addressing the JIRA issue * can be autowired via {@link org.springframework.beans.factory.annotation.Autowired @Inject},
* raised in <a * specifically addressing SPR-4040.
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
* target="_blank">SPR-4040</a>.
*/ */
@Test @Test
public void testBeanAutowiredWithFactoryBean() { public void testBeanAutowiredWithFactoryBean() {
@ -1315,7 +1313,7 @@ public class InjectAnnotationBeanPostProcessorTests {
public static class StringFactoryBean implements FactoryBean<String> { public static class StringFactoryBean implements FactoryBean<String> {
@Override @Override
public String getObject() throws Exception { public String getObject() {
return ""; return "";
} }

10
spring-core/src/main/java/org/springframework/core/ResolvableType.java

@ -430,7 +430,8 @@ public class ResolvableType implements Serializable {
if (this == NONE) { if (this == NONE) {
return NONE; return NONE;
} }
if (ObjectUtils.nullSafeEquals(resolve(), type)) { Class<?> resolved = resolve();
if (resolved == null || resolved == type) {
return this; return this;
} }
for (ResolvableType interfaceType : getInterfaces()) { for (ResolvableType interfaceType : getInterfaces()) {
@ -468,7 +469,7 @@ public class ResolvableType implements Serializable {
*/ */
public ResolvableType[] getInterfaces() { public ResolvableType[] getInterfaces() {
Class<?> resolved = resolve(); Class<?> resolved = resolve();
if (resolved == null || ObjectUtils.isEmpty(resolved.getGenericInterfaces())) { if (resolved == null || resolved.getGenericInterfaces().length == 0) {
return EMPTY_TYPES_ARRAY; return EMPTY_TYPES_ARRAY;
} }
ResolvableType[] interfaces = this.interfaces; ResolvableType[] interfaces = this.interfaces;
@ -818,7 +819,7 @@ public class ResolvableType implements Serializable {
@Nullable @Nullable
private Type resolveBounds(Type[] bounds) { private Type resolveBounds(Type[] bounds) {
if (ObjectUtils.isEmpty(bounds) || Object.class == bounds[0]) { if (bounds.length == 0 || bounds[0] == Object.class) {
return null; return null;
} }
return bounds[0]; return bounds[0];
@ -1638,6 +1639,9 @@ public class ResolvableType implements Serializable {
} }
/**
* Internal {@link Type} used to represent an empty value.
*/
@SuppressWarnings("serial") @SuppressWarnings("serial")
static class EmptyType implements Type, Serializable { static class EmptyType implements Type, Serializable {

Loading…
Cancel
Save