Gabriel Roldán created GEOS-5073: ------------------------------------ Summary: org.geoserver.catalog.impl.ProxyList is said to be immutable, but it's not Key: GEOS-5073 URL: https://jira.codehaus.org/browse/GEOS-5073 Project: GeoServer Issue Type: Bug Components: Configuration Affects Versions: 2.2-beta1 Reporter: Gabriel Roldán Assignee: Gabriel Roldán Fix For: 2.2-beta2
The following patch is all what's needed for the default Catalog to truly return immutable lists. All tests still pass except the one patched, which was asserting the immutable list was mutable. {code} --- a/src/main/src/main/java/org/geoserver/catalog/impl/ProxyList.java +++ b/src/main/src/main/java/org/geoserver/catalog/impl/ProxyList.java @@ -4,7 +4,6 @@ */ package org.geoserver.catalog.impl; -import java.lang.reflect.Proxy; import java.util.AbstractList; import java.util.List; @@ -35,12 +34,8 @@ public abstract class ProxyList extends AbstractList { @Override public Object set(int index, Object element) { - if ( !proxyInterface.isInstance( element ) || !(element instanceof Proxy) ) { throw new IllegalArgumentException( "Object is not a proxy, or not a proxy of the correct type"); - } - - return proxyList.set(index, unwrapProxy(element, proxyInterface)); } public int size() { diff --git a/src/main/src/test/java/org/geoserver/catalog/impl/CatalogImplTest.java b/src/main/src/test/java/org/geoserver/catalog/impl/CatalogImplTest.java index 6bee7b8..7a2410a 100644 --- a/src/main/src/test/java/org/geoserver/catalog/impl/CatalogImplTest.java +++ b/src/main/src/test/java/org/geoserver/catalog/impl/CatalogImplTest.java @@ -1386,16 +1386,22 @@ public class CatalogImplTest extends TestCase { List<StyleInfo> styles = catalog.getStyles(); assertEquals( 2 , styles.size() ); - assertEquals( s.getName(), styles.get( 0 ).getName() ); - assertEquals( "a"+s.getName(), styles.get( 1).getName() ); - - //test sorting - Collections.sort( styles, new Comparator<StyleInfo>() { + //test immutability + Comparator<StyleInfo> comparator = new Comparator<StyleInfo>() { public int compare(StyleInfo o1, StyleInfo o2) { return o1.getName().compareTo( o2.getName()); } - }); + }; + try { + Collections.sort(styles, comparator); + fail("Expected runtime exception, immutable collection"); + } catch (RuntimeException e) { + assertTrue(true); + } + + styles = new ArrayList<StyleInfo>(styles); + Collections.sort(styles, comparator); assertEquals( "a"+s.getName(), styles.get( 0 ).getName() ); assertEquals( s.getName(), styles.get( 1 ).getName() ); {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Geoserver-devel mailing list Geoserver-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geoserver-devel