-
Bug
-
Resolution: Fixed
-
P3
-
None
-
None
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8206782 | 12 | Martin Buchholz | P3 | Resolved | Fixed | team |
JDK-8206559 | 11.0.1 | Martin Buchholz | P3 | Resolved | Fixed | b01 |
Colleague Tobias Thierer writes:
Classes that delegate/forward calls to a wrapped class normally want to override all methods, including ones that are nonabstract in the super class (eg. interface default methods); otherwise, a custom overridden implementation in the wrapped class would be replaced with the super / default behavior.
However there are three Iterator implementations in java/util/Collections.java that delegate to another iterator but which use the super, rather than delegate, implementation of forEachRemaining(). This looks like an oversight from when default methods were introduced in OpenJDK 8.
This affects at least the following methods / implementations:
UnmodifiableEntrySetSpliterator.iterator()
CheckedCollection.iterator()
CheckedEntrySet.iterator()
I'm attaching a test that demonstrates the oversight. The test uses iterator implementations that override forEachRemaining() to throw UnsupportedOperationException - just as an easily tested placeholder for more reasonable ways that an application may want to override forEachRemaining().
Perhaps those Iterator implementations might want to override forEachRemaining() to call the delegate implementation of forEachRemaining(), rather than the super implementation?
Classes that delegate/forward calls to a wrapped class normally want to override all methods, including ones that are nonabstract in the super class (eg. interface default methods); otherwise, a custom overridden implementation in the wrapped class would be replaced with the super / default behavior.
However there are three Iterator implementations in java/util/Collections.java that delegate to another iterator but which use the super, rather than delegate, implementation of forEachRemaining(). This looks like an oversight from when default methods were introduced in OpenJDK 8.
This affects at least the following methods / implementations:
UnmodifiableEntrySetSpliterator.iterator()
CheckedCollection.iterator()
CheckedEntrySet.iterator()
I'm attaching a test that demonstrates the oversight. The test uses iterator implementations that override forEachRemaining() to throw UnsupportedOperationException - just as an easily tested placeholder for more reasonable ways that an application may want to override forEachRemaining().
Perhaps those Iterator implementations might want to override forEachRemaining() to call the delegate implementation of forEachRemaining(), rather than the super implementation?
- backported by
-
JDK-8206559 Delegating Iterator implementations that don't delegate forEachRemaining()
-
- Resolved
-
-
JDK-8206782 Delegating Iterator implementations that don't delegate forEachRemaining()
-
- Resolved
-
- relates to
-
JDK-8292317 Missing null check for Iterator.forEachRemaining implementations
-
- Closed
-