24
24
import java .util .Collection ;
25
25
import java .util .Collections ;
26
26
import java .util .HashMap ;
27
+ import java .util .Iterator ;
27
28
import java .util .LinkedHashMap ;
28
29
import java .util .LinkedHashSet ;
29
30
import java .util .List ;
31
+ import java .util .ListIterator ;
30
32
import java .util .Map ;
31
33
import java .util .Properties ;
32
34
import java .util .concurrent .atomic .AtomicInteger ;
@@ -1853,6 +1855,28 @@ public void SPR11609() {
1853
1855
assertEquals (1 , exp .getValue (sec ));
1854
1856
}
1855
1857
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
+
1856
1880
1857
1881
private static enum ABC { A , B , C }
1858
1882
@@ -1865,21 +1889,21 @@ public static class BooleanHolder {
1865
1889
1866
1890
private boolean primitiveProperty = true ;
1867
1891
1868
- public Boolean isSimpleProperty () {
1869
- return simpleProperty ;
1870
- }
1871
-
1872
1892
public void setSimpleProperty (Boolean simpleProperty ) {
1873
1893
this .simpleProperty = simpleProperty ;
1874
1894
}
1875
1895
1876
- public boolean isPrimitiveProperty () {
1877
- return primitiveProperty ;
1896
+ public Boolean isSimpleProperty () {
1897
+ return this . simpleProperty ;
1878
1898
}
1879
1899
1880
1900
public void setPrimitiveProperty (boolean primitiveProperty ) {
1881
1901
this .primitiveProperty = primitiveProperty ;
1882
1902
}
1903
+
1904
+ public boolean isPrimitiveProperty () {
1905
+ return this .primitiveProperty ;
1906
+ }
1883
1907
}
1884
1908
1885
1909
@@ -1932,13 +1956,13 @@ public static class Spr10486 {
1932
1956
1933
1957
private String name = "name" ;
1934
1958
1935
- public String getName () {
1936
- return name ;
1937
- }
1938
-
1939
1959
public void setName (String name ) {
1940
1960
this .name = name ;
1941
1961
}
1962
+
1963
+ public String getName () {
1964
+ return this .name ;
1965
+ }
1942
1966
}
1943
1967
1944
1968
@@ -1950,25 +1974,22 @@ public String isSomething() {
1950
1974
}
1951
1975
1952
1976
1953
- static class TestClass2 { // SPR-9194
1977
+ static class TestClass2 { // SPR-9194
1954
1978
1955
1979
String string ;
1956
1980
1957
-
1958
1981
public TestClass2 (String string ) {
1959
1982
this .string = string ;
1960
1983
}
1961
1984
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 ))) ;
1965
1988
}
1966
1989
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 ();
1972
1993
}
1973
1994
}
1974
1995
@@ -1982,12 +2003,12 @@ public int echo(int invocation) {
1982
2003
}
1983
2004
1984
2005
public int parameter () {
1985
- return counter .incrementAndGet ();
2006
+ return this . counter .incrementAndGet ();
1986
2007
}
1987
2008
1988
2009
@ Override
1989
2010
public Object resolve (EvaluationContext context , String beanName ) throws AccessException {
1990
- return beanName .equals ("bean" ) ? this : null ;
2011
+ return ( beanName .equals ("bean" ) ? this : null ) ;
1991
2012
}
1992
2013
}
1993
2014
@@ -1997,4 +2018,135 @@ public static class MapWithConstant extends HashMap {
1997
2018
public static final int X = 1 ;
1998
2019
}
1999
2020
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
+
2000
2152
}
0 commit comments