diff --git a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java index 40a96e5b25..5d9c0becb1 100644 --- a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java +++ b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-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. @@ -57,6 +57,19 @@ public class CandidateComponentsIndex { this.index = parseIndex(content); } + private static MultiValueMap parseIndex(List content) { + MultiValueMap index = new LinkedMultiValueMap<>(); + for (Properties entry : content) { + entry.forEach((type, values) -> { + String[] stereotypes = ((String) values).split(","); + for (String stereotype : stereotypes) { + index.add(stereotype, new Entry((String) type)); + } + }); + } + return index; + } + /** * Return the candidate types that are associated with the specified stereotype. @@ -76,21 +89,11 @@ public class CandidateComponentsIndex { return Collections.emptySet(); } - private static MultiValueMap parseIndex(List content) { - MultiValueMap index = new LinkedMultiValueMap<>(); - for (Properties entry : content) { - entry.forEach((type, values) -> { - String[] stereotypes = ((String) values).split(","); - for (String stereotype : stereotypes) { - index.add(stereotype, new Entry((String) type)); - } - }); - } - return index; - } private static class Entry { + private final String type; + private final String packageName; Entry(String type) { @@ -106,7 +109,6 @@ public class CandidateComponentsIndex { return this.type.startsWith(basePackage); } } - } } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java index bb662105c3..85eca580af 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java @@ -300,7 +300,7 @@ public class ClassPathScanningCandidateComponentProviderTests { } @Test - public void testWithAspectAnnotationOnly() throws Exception { + public void testWithAspectAnnotationOnly() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class)); Set candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE); diff --git a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java index 2eac4a6688..cba866107c 100644 --- a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java +++ b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java @@ -27,11 +27,6 @@ import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; - - - - - /** * Tests for {@link CandidateComponentsIndexLoader}. * @@ -92,7 +87,7 @@ public class CandidateComponentsIndexLoaderTests { } @Test - public void loadIndexNoEntry() throws IOException { + public void loadIndexNoEntry() { CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex( CandidateComponentsTestClassLoader.index(getClass().getClassLoader(), new ClassPathResource("empty-spring.components", getClass()))); @@ -100,7 +95,7 @@ public class CandidateComponentsIndexLoaderTests { } @Test - public void loadIndexWithException() throws IOException { + public void loadIndexWithException() { final IOException cause = new IOException("test exception"); assertThatIllegalStateException().isThrownBy(() -> { CandidateComponentsTestClassLoader classLoader = new CandidateComponentsTestClassLoader(getClass().getClassLoader(), cause); diff --git a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java index 70a9903462..ab94bfd456 100644 --- a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java +++ b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java @@ -25,10 +25,6 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; - - - - /** * Tests for {@link CandidateComponentsIndex}. * diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java index f19399df8b..1f4c0ba5c9 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -140,12 +140,12 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { @Override public Set getAnnotatedMethods(String annotationName) { Set annotatedMethods = null; - for (int i = 0; i < this.annotatedMethods.length; i++) { - if (this.annotatedMethods[i].isAnnotated(annotationName)) { + for (MethodMetadata annotatedMethod : this.annotatedMethods) { + if (annotatedMethod.isAnnotated(annotationName)) { if (annotatedMethods == null) { annotatedMethods = new LinkedHashSet<>(4); } - annotatedMethods.add(this.annotatedMethods[i]); + annotatedMethods.add(annotatedMethod); } } return annotatedMethods != null ? annotatedMethods : Collections.emptySet();