[java-support] branch main updated: Add an Iterator wrapper allowing reflective iteration on Java 17.
Scott Cantor
cantor.2 at osu.edu
Tue Feb 1 18:52:04 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=181ab99a354115bf01743df8c5a903446cc9196d
The following commit(s) were added to refs/heads/main by this push:
new 181ab99 Add an Iterator wrapper allowing reflective iteration on Java 17.
181ab99 is described below
commit 181ab99a354115bf01743df8c5a903446cc9196d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Feb 1 13:52:01 2022 -0500
Add an Iterator wrapper allowing reflective iteration on Java 17.
---
.../support/collection/ReflectionSafeIterator.java | 62 ++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/ReflectionSafeIterator.java b/src/main/java/net/shibboleth/utilities/java/support/collection/ReflectionSafeIterator.java
new file mode 100644
index 0000000..28dd168
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/ReflectionSafeIterator.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.utilities.java.support.collection;
+
+import java.util.Iterator;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * Wrapper class for delegating publically to {@link Iterator} implementations that
+ * may themselves be private.
+ *
+ * <p>This addresses bugs in Java that result from old implementations of collection classes
+ * that were never cleaned up to work properly in Java 17+ after access to JDK internals was
+ * clossed off.</p>
+ *
+ * @param <T> iterator type
+ *
+ * @since 8.2.0
+ */
+public class ReflectionSafeIterator<T> implements Iterator<T> {
+
+ /** Wrapped iterator. */
+ @Nonnull private final Iterator<T> iter;
+
+ /**
+ * Constructor.
+ *
+ * @param i iterator to wrap
+ */
+ public ReflectionSafeIterator(@Nonnull final Iterator<T> i) {
+ iter = Constraint.isNotNull(i, "Wrapped Iterator cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ /** {@inheritDoc} */
+ public T next() {
+ return iter.next();
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list