[jdom-interest] Possible bug in JDom2

Rolf Lear jdom at tuis.net
Mon Mar 19 03:24:56 PDT 2012


In one sense, it would make sense to be a list, but the actual iterator 
returned is 'live', but a list could not be (I don't think).

As it is, even the iterator is complex enough, a list I think would be 
too challenging (and slow) to contemplate.... although it is worth 
investigating it further. Maybe my off-the-cuff assessment is wrong?

The iterator returned is read/write, but I can't see a way to make the 
list modifiable.

Still, I am open to some suggestions. I don't think I can get a working 
version of that out in less than a week or so, and that would be too 
long for an easter release, I think. If anyone is interested in taking a 
stab at making a list-based return type for getDescendants then I would 
happily consider it...

I will still take an hour or so to look in to the feasability some more

Rolf

On 19/03/2012 4:22 AM, Noel Grandin wrote:
> I would have thought that it should return some Collection sub-class,
> e.g. List
>
> Since we're cleaning things up in JDOM2, now seems like a good time to
> make a change like that.
>
> On 2012-03-15 23:59, Rolf Lear wrote:
>> Hi Craig.
>>
>> getDescendants returns an Iterator<Element> not an Iterable<Element>
>>
>> Now that I think about it, it is a mess, but, that's because JDOM 1.x
>> returned an iterator.
>>
>> Technically your code should be:
>>
>> for (Iterator<Element> it =root.getDescendants(tableFilter);
>> it.hasNext(); ) {
>> tableCount++;
>> }
>>
>> I wonder whether I can make an 'Iterable' return value too.... it
>> makes sense to, but I can't change the current return value for
>> getDescendants without breaking compatibility...
>>
>>
>> suggestions?
>>
>> Rolf
>>
>>
>>
>> On 15/03/2012 3:59 PM, Craig Noah wrote:
>>> I've downloaded the latest JDom2 beta today and am working to
>>> incorporate it into some new code. I am developing against Java6, so
>>> I would expect iterators to work. However, the following code fails
>>> to compile (with JDom2 includes):
>>>
>>> SAXBuilder sax = new SAXBuilder();
>>> Document xml = sax.build (source); // source is a File object
>>> Element root = xml.getRootElement();
>>> ElementFilter tableFilter = new ElementFilter ("Table");
>>> int tableCount = 0;
>>> for (Element table : root.getDescendants(
>>> tableFilter)) {
>>> tableCount++;
>>> }
>>>
>>> The compile-time error that I get states, "Can only iterate over an
>>> array or an instance of java.lang.Iterable". Since
>>> Element.getDescendants (Filter<F>) returns a java.util.Iterator<F>, I
>>> would expect my code to compile and work. What am I missing?
>>>
>>> Sincerely,
>>> Craig
>>>
>>>
>>> _______________________________________________
>>> To control your jdom-interest membership:
>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>>
>>
>>
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
>
> ------------------------------------------------------------------------
> Disclaimer: http://www.peralex.com/disclaimer.html
>



More information about the jdom-interest mailing list