Skip to content

Commit 7fa3e65

Browse files
committed
Test for cyclic type declaration handling in TypeDescriptor
Issue: SPR-9735
1 parent 329ba2a commit 7fa3e65

File tree

1 file changed

+174
-22
lines changed

1 file changed

+174
-22
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java

Lines changed: 174 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import java.util.Collection;
2525
import java.util.Collections;
2626
import java.util.HashMap;
27+
import java.util.Iterator;
2728
import java.util.LinkedHashMap;
2829
import java.util.LinkedHashSet;
2930
import java.util.List;
31+
import java.util.ListIterator;
3032
import java.util.Map;
3133
import java.util.Properties;
3234
import java.util.concurrent.atomic.AtomicInteger;
@@ -1853,6 +1855,28 @@ public void SPR11609() {
18531855
assertEquals(1, exp.getValue(sec));
18541856
}
18551857

1858+
@Test
1859+
public void SPR9735() {
1860+
Item item = new Item();
1861+
item.setName("parent");
1862+
1863+
Item item1 = new Item();
1864+
item1.setName("child1");
1865+
1866+
Item item2 = new Item();
1867+
item2.setName("child2");
1868+
1869+
item.add(item1);
1870+
item.add(item2);
1871+
1872+
ExpressionParser parser = new SpelExpressionParser();
1873+
EvaluationContext context = new StandardEvaluationContext();
1874+
Expression exp = parser.parseExpression("#item[0].name");
1875+
context.setVariable("item", item);
1876+
1877+
assertEquals("child1", exp.getValue(context));
1878+
}
1879+
18561880

18571881
private static enum ABC { A, B, C }
18581882

@@ -1865,21 +1889,21 @@ public static class BooleanHolder {
18651889

18661890
private boolean primitiveProperty = true;
18671891

1868-
public Boolean isSimpleProperty() {
1869-
return simpleProperty;
1870-
}
1871-
18721892
public void setSimpleProperty(Boolean simpleProperty) {
18731893
this.simpleProperty = simpleProperty;
18741894
}
18751895

1876-
public boolean isPrimitiveProperty() {
1877-
return primitiveProperty;
1896+
public Boolean isSimpleProperty() {
1897+
return this.simpleProperty;
18781898
}
18791899

18801900
public void setPrimitiveProperty(boolean primitiveProperty) {
18811901
this.primitiveProperty = primitiveProperty;
18821902
}
1903+
1904+
public boolean isPrimitiveProperty() {
1905+
return this.primitiveProperty;
1906+
}
18831907
}
18841908

18851909

@@ -1932,13 +1956,13 @@ public static class Spr10486 {
19321956

19331957
private String name = "name";
19341958

1935-
public String getName() {
1936-
return name;
1937-
}
1938-
19391959
public void setName(String name) {
19401960
this.name = name;
19411961
}
1962+
1963+
public String getName() {
1964+
return this.name;
1965+
}
19421966
}
19431967

19441968

@@ -1950,25 +1974,22 @@ public String isSomething() {
19501974
}
19511975

19521976

1953-
static class TestClass2 { // SPR-9194
1977+
static class TestClass2 { // SPR-9194
19541978

19551979
String string;
19561980

1957-
19581981
public TestClass2(String string) {
19591982
this.string = string;
19601983
}
19611984

1962-
@Override
1963-
public int hashCode() {
1964-
return 0;
1985+
public boolean equals(Object other) {
1986+
return (this == other || (other instanceof TestClass2 &&
1987+
this.string.equals(((TestClass2) other).string)));
19651988
}
19661989

1967-
public boolean equals(Object o) {
1968-
if (o instanceof TestClass2) {
1969-
return string.equals(((TestClass2) o).string);
1970-
}
1971-
return false;
1990+
@Override
1991+
public int hashCode() {
1992+
return this.string.hashCode();
19721993
}
19731994
}
19741995

@@ -1982,12 +2003,12 @@ public int echo(int invocation) {
19822003
}
19832004

19842005
public int parameter() {
1985-
return counter.incrementAndGet();
2006+
return this.counter.incrementAndGet();
19862007
}
19872008

19882009
@Override
19892010
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
1990-
return beanName.equals("bean") ? this : null;
2011+
return (beanName.equals("bean") ? this : null);
19912012
}
19922013
}
19932014

@@ -1997,4 +2018,135 @@ public static class MapWithConstant extends HashMap {
19972018
public static final int X = 1;
19982019
}
19992020

2021+
2022+
public class Item implements List<Item> {
2023+
2024+
private String name;
2025+
2026+
private List<Item> children = new ArrayList<Item>();
2027+
2028+
public void setName(String name) {
2029+
this.name = name;
2030+
}
2031+
2032+
public String getName() {
2033+
return this.name;
2034+
}
2035+
2036+
@Override
2037+
public int size() {
2038+
return this.children.size();
2039+
}
2040+
2041+
@Override
2042+
public boolean isEmpty() {
2043+
return this.children.isEmpty();
2044+
}
2045+
2046+
@Override
2047+
public boolean contains(Object o) {
2048+
return this.children.contains(o);
2049+
}
2050+
2051+
@Override
2052+
public Iterator<Item> iterator() {
2053+
return this.children.iterator();
2054+
}
2055+
2056+
@Override
2057+
public Object[] toArray() {
2058+
return this.children.toArray();
2059+
}
2060+
2061+
@Override
2062+
public <T> T[] toArray(T[] a) {
2063+
return this.children.toArray(a);
2064+
}
2065+
2066+
@Override
2067+
public boolean add(Item e) {
2068+
return this.children.add(e);
2069+
}
2070+
2071+
@Override
2072+
public boolean remove(Object o) {
2073+
return this.children.remove(o);
2074+
}
2075+
2076+
@Override
2077+
public boolean containsAll(Collection<?> c) {
2078+
return this.children.containsAll(c);
2079+
}
2080+
2081+
@Override
2082+
public boolean addAll(Collection<? extends Item> c) {
2083+
return this.children.addAll(c);
2084+
}
2085+
2086+
@Override
2087+
public boolean addAll(int index, Collection<? extends Item> c) {
2088+
return this.children.addAll(index, c);
2089+
}
2090+
2091+
@Override
2092+
public boolean removeAll(Collection<?> c) {
2093+
return this.children.removeAll(c);
2094+
}
2095+
2096+
@Override
2097+
public boolean retainAll(Collection<?> c) {
2098+
return this.children.retainAll(c);
2099+
}
2100+
2101+
@Override
2102+
public void clear() {
2103+
this.children.clear();
2104+
}
2105+
2106+
@Override
2107+
public Item get(int index) {
2108+
return this.children.get(index);
2109+
}
2110+
2111+
@Override
2112+
public Item set(int index, Item element) {
2113+
return this.children.set(index, element);
2114+
}
2115+
2116+
@Override
2117+
public void add(int index, Item element) {
2118+
this.children.add(index, element);
2119+
}
2120+
2121+
@Override
2122+
public Item remove(int index) {
2123+
return this.children.remove(index);
2124+
}
2125+
2126+
@Override
2127+
public int indexOf(Object o) {
2128+
return this.children.indexOf(o);
2129+
}
2130+
2131+
@Override
2132+
public int lastIndexOf(Object o) {
2133+
return this.children.lastIndexOf(o);
2134+
}
2135+
2136+
@Override
2137+
public ListIterator<Item> listIterator() {
2138+
return this.children.listIterator();
2139+
}
2140+
2141+
@Override
2142+
public ListIterator<Item> listIterator(int index) {
2143+
return this.children.listIterator(index);
2144+
}
2145+
2146+
@Override
2147+
public List<Item> subList(int fromIndex, int toIndex) {
2148+
return this.children.subList(fromIndex, toIndex);
2149+
}
2150+
}
2151+
20002152
}

0 commit comments

Comments
 (0)