Skip to content

Commit e14c2de

Browse files
committed
ImportStack extends ArrayDeque instead of Stack and relies on standard contains implementation
Issue: SPR-13852
1 parent 5d4547d commit e14c2de

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,10 +18,12 @@
1818

1919
import java.io.FileNotFoundException;
2020
import java.io.IOException;
21+
import java.util.ArrayDeque;
2122
import java.util.ArrayList;
2223
import java.util.Collection;
2324
import java.util.Collections;
2425
import java.util.Comparator;
26+
import java.util.Deque;
2527
import java.util.HashMap;
2628
import java.util.Iterator;
2729
import java.util.LinkedHashMap;
@@ -30,7 +32,6 @@
3032
import java.util.List;
3133
import java.util.Map;
3234
import java.util.Set;
33-
import java.util.Stack;
3435

3536
import org.apache.commons.logging.Log;
3637
import org.apache.commons.logging.LogFactory;
@@ -625,7 +626,7 @@ public SourceClass asSourceClass(String className) throws IOException {
625626

626627

627628
@SuppressWarnings("serial")
628-
private static class ImportStack extends Stack<ConfigurationClass> implements ImportRegistry {
629+
private static class ImportStack extends ArrayDeque<ConfigurationClass> implements ImportRegistry {
629630

630631
private final MultiValueMap<String, AnnotationMetadata> imports = new LinkedMultiValueMap<String, AnnotationMetadata>();
631632

@@ -650,23 +651,6 @@ public AnnotationMetadata getImportingClassFor(String importedClass) {
650651
return (!CollectionUtils.isEmpty(list) ? list.get(list.size() - 1) : null);
651652
}
652653

653-
/**
654-
* Simplified contains() implementation that tests to see if any {@link ConfigurationClass}
655-
* exists within this stack that has the same name as <var>elem</var>. Elem must be of
656-
* type ConfigurationClass.
657-
*/
658-
@Override
659-
public boolean contains(Object elem) {
660-
ConfigurationClass configClass = (ConfigurationClass) elem;
661-
Comparator<ConfigurationClass> comparator = new Comparator<ConfigurationClass>() {
662-
@Override
663-
public int compare(ConfigurationClass first, ConfigurationClass second) {
664-
return (first.getMetadata().getClassName().equals(second.getMetadata().getClassName()) ? 0 : 1);
665-
}
666-
};
667-
return (Collections.binarySearch(this, configClass, comparator) != -1);
668-
}
669-
670654
/**
671655
* Given a stack containing (in order)
672656
* <ul>
@@ -886,7 +870,7 @@ public String toString() {
886870
*/
887871
private static class CircularImportProblem extends Problem {
888872

889-
public CircularImportProblem(ConfigurationClass attemptedImport, Stack<ConfigurationClass> importStack) {
873+
public CircularImportProblem(ConfigurationClass attemptedImport, Deque<ConfigurationClass> importStack) {
890874
super(String.format("A circular @Import has been detected: " +
891875
"Illegal attempt by @Configuration class '%s' to import class '%s' as '%s' is " +
892876
"already present in the current import stack %s", importStack.peek().getSimpleName(),

0 commit comments

Comments
 (0)