Project

Profile

Help

Maintenance. Planio will be undergoing a scheduled maintenance this weekend. Between Saturday, July 24 at 9:00 UTC and Sunday, July 25, 22:00 UTC your account might observe occasional downtimes which may last up to several minutes in some cases.

Bug #4890

DotNetIterator class doesn't implement hasNext() correctly

Added by Michael Kay 6 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Low
Category:
.NET API
Sprint/Milestone:
-
Start date:
2021-02-04
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:

Description

This problem may be asymptomatic, but the class net.sf.saxon.dotnet.DotNetIterator, which is used on the .NET product to bridge a C# IEnumerator to a Java Iterator, is incorrect. According to the contract for java.lang.Iterator, the hasNext() method should leave the state of the iterator unchanged, but we're calling MoveNext(), which means that if you make two calls on hasNext() without an intervening call on next(), the iterator will change position.

It works so long as the caller calls hasNext() exactly once between successive calls on next().

History

#1 Updated by Michael Kay 6 months ago

  • Subject changed from DotNotIterator doesn't implement hasNext() correctly to DotNetIterator class doesn't implement hasNext() correctly

#2 Updated by Michael Kay 6 months ago

I think the correct logic would be:

public class IteratorFromEnumerator<T> : java.util.Iterator<T> {
        private IEnumerator<T> enumerator;
        private bool moreToCome ;
        public IteratorFromEnumerator(IEnumerator<T> enumerator) {
            this.enumerator = enumerator;
            this.moreToCome = enumerator.MoveNext();
        }
        public bool hasNext() {
            return moreToCome;
        }

        public T next() {
            T nextItem = enumerator.Current;
            this.moreToCome = enumerator.MoveNext();
            return nextItem;
        }
    }

#3 Updated by O'Neil Delpratt 4 months ago

  • Assignee changed from Michael Kay to O'Neil Delpratt

#4 Updated by O'Neil Delpratt 4 months ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100
  • Applies to branch 10 added
  • Fix Committed on Branch 10, trunk added

Bug fixed and committed to git repository.

#5 Updated by O'Neil Delpratt 3 months ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 10.5 added

Bug fix applied to Saxon 10.5 maintenance release.

Please register to edit this issue

Also available in: Atom PDF