Hi Andrea;

What you describe is going to take me a moment to understand.
> Hi,
> I had a strange issue today with GeoServer. Trying out a request
> that would end up making a feature collection, and passing it
> to FreeMarker I got a long stack trace that basically
> just complained that an iterator said there were features, just
> to throw an exception when calling next()...
>   
So hasNext() returned true? And then calling next() threw an exception?
> At first I was quite baffled because the above exception was
> not really returning me any info.
> Debugging the code I noticed that if an exception occurred
> trying to create the iterator in DataFeatureCollection
> a new NoContentIterator holding the exception was created.
> That iterator returned true to hasNext(), and then threw
> the exception it was holing on next().
>   
So there is an exception (ie a real problem?) Sometimes we can only tell 
when trying
to read content for the first time; but usually the FeatureCollection 
constructor can
throw an IOException.
> Can't we just kill NoContentIterator and throw the exception
> in the very place where it did originate?
>   
I would prefer to throw the exception when the FeatureCollection is 
created (that is where the user took action to cause the problem).
I would find that more helpful than creating a FeatureCollection and 
getting the error when trying to access it.

The current functionality makes sense to me; you can an error when you 
try an access the collection. iterator() and next() are not methods
that screen "access" to me; actually grabbing some content out using 
next() is a good place to either return content or throw an exeption.

FeatureCollection collection = source.getFeatures(); // Should throw 
IOException if we cannot connect
Iterator iterator = collection.iterator(); // currently does not produce 
errors; is "lazy"
while ( iterator.hasNext() ){ // can try and connect; but should return 
false if their is no content?
    Feature f = (Feature) iterator.next(); // another good place to 
throw an exception
}
finally {
   collection.close( iterator );
}


Jody

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to