Skip to content

Commit 77b8f4d

Browse files
committed
ImportStack extends ArrayDeque instead of Stack and relies on standard contains implementation
Issue: SPR-13852 (cherry picked from commit e14c2de)
1 parent 8516de6 commit 77b8f4d

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;
@@ -622,7 +623,7 @@ public SourceClass asSourceClass(String className) throws IOException {
622623

623624

624625
@SuppressWarnings("serial")
625-
private static class ImportStack extends Stack<ConfigurationClass> implements ImportRegistry {
626+
private static class ImportStack extends ArrayDeque<ConfigurationClass> implements ImportRegistry {
626627

627628
private final MultiValueMap<String, AnnotationMetadata> imports = new LinkedMultiValueMap<String, AnnotationMetadata>();
628629

@@ -647,23 +648,6 @@ public AnnotationMetadata getImportingClassFor(String importedClass) {
647648
return (!CollectionUtils.isEmpty(list) ? list.get(list.size() - 1) : null);
648649
}
649650

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

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

0 commit comments

Comments
 (0)