From 6d77f1cf3b3f060ead70d49079bc87d75e0b105c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 31 Jan 2013 16:51:56 +0100 Subject: [PATCH] ConfigurationClassPostProcessor consistently uses ClassLoader, not loading core JDK annotations via ASM Issue: SPR-10249 --- .../annotation/ConfigurationClassParser.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 2901e5cea0d..c03aca61ddf 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -54,6 +54,7 @@ import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.AssignableTypeFilter; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import static org.springframework.context.annotation.MetadataUtils.*; @@ -228,7 +229,7 @@ class ConfigurationClassParser { // process any @Import annotations Set imports = getImports(metadata.getClassName(), null, new HashSet()); - if (imports != null && !imports.isEmpty()) { + if (!CollectionUtils.isEmpty(imports)) { processImport(configClass, imports.toArray(new String[imports.size()]), true); } @@ -292,9 +293,8 @@ class ConfigurationClassParser { * @return a set of all {@link Import#value() import values} or {@code null} * @throws IOException if there is any problem reading metadata from the named class */ - private Set getImports(String className, Set imports, - Set visited) throws IOException { - if (visited.add(className)) { + private Set getImports(String className, Set imports, Set visited) throws IOException { + if (visited.add(className) && !className.startsWith("java")) { AnnotationMetadata metadata = metadataReaderFactory.getMetadataReader(className).getAnnotationMetadata(); for (String annotationType : metadata.getAnnotationTypes()) { imports = getImports(annotationType, imports, visited); @@ -331,7 +331,7 @@ class ConfigurationClassParser { throw new IllegalStateException(ex); } } - else if (new AssignableTypeFilter(ImportBeanDefinitionRegistrar.class).match(reader, metadataReaderFactory)) { + else if (new AssignableTypeFilter(ImportBeanDefinitionRegistrar.class).match(reader, this.metadataReaderFactory)) { // the candidate class is an ImportBeanDefinitionRegistrar -> delegate to it to register additional bean definitions try { ImportBeanDefinitionRegistrar registrar = BeanUtils.instantiateClass( @@ -360,17 +360,16 @@ class ConfigurationClassParser { private void invokeAwareMethods(ImportBeanDefinitionRegistrar registrar) { if (registrar instanceof Aware) { if (registrar instanceof ResourceLoaderAware) { - ((ResourceLoaderAware) registrar).setResourceLoader(resourceLoader); + ((ResourceLoaderAware) registrar).setResourceLoader(this.resourceLoader); } if (registrar instanceof BeanClassLoaderAware) { - ClassLoader classLoader = - registry instanceof ConfigurableBeanFactory ? - ((ConfigurableBeanFactory) registry).getBeanClassLoader() : - resourceLoader.getClassLoader(); + ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ? + ((ConfigurableBeanFactory) this.registry).getBeanClassLoader() : + this.resourceLoader.getClassLoader()); ((BeanClassLoaderAware) registrar).setBeanClassLoader(classLoader); } - if (registrar instanceof BeanFactoryAware && registry instanceof BeanFactory) { - ((BeanFactoryAware) registrar).setBeanFactory((BeanFactory) registry); + if (registrar instanceof BeanFactoryAware && this.registry instanceof BeanFactory) { + ((BeanFactoryAware) registrar).setBeanFactory((BeanFactory) this.registry); } } } @@ -398,6 +397,7 @@ class ConfigurationClassParser { return this.importStack; } + interface ImportRegistry { String getImportingClassFor(String importedClass); @@ -470,4 +470,5 @@ class ConfigurationClassParser { new Location(importStack.peek().getResource(), metadata)); } } + }