nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java Mon Oct 19 08:39:06 2015 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java Mon Oct 19 08:45:29 2015 +0200
@@ -87,6 +87,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Objects;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.LinkRequest;
@@ -94,10 +95,12 @@
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
/**
- * A composite type-based guarding dynamic linker. When a receiver of a not yet seen class is encountered, all linkers
- * are queried sequentially on their {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} method. The linkers
- * returning true are then bound to the class, and next time a receiver of same type is encountered, the linking is
- * delegated to those linkers only, speeding up dispatch.
+ * A composite type-based guarding dynamic linker. When a receiver of a not yet
+ * seen class is encountered, all linkers are queried sequentially on their
+ * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} method. The linkers
+ * returning true are then bound to the class, and next time a receiver of same
+ * type is encountered, the linking is delegated to those linkers only, speeding
+ * up dispatch.
*/
public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable {
private static final long serialVersionUID = 1L;
@@ -149,15 +152,24 @@
* Creates a new composite type-based linker.
*
* @param linkers the component linkers
+ * @throws NullPointerException if {@code linkers} or any of its elements
+ * are null.
*/
public CompositeTypeBasedGuardingDynamicLinker(final Iterable<? extends TypeBasedGuardingDynamicLinker> linkers) {
final List<TypeBasedGuardingDynamicLinker> l = new LinkedList<>();
for(final TypeBasedGuardingDynamicLinker linker: linkers) {
- l.add(linker);
+ l.add(Objects.requireNonNull(linker));
}
this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()]));
}
+ /**
+ * Returns true if any of the composite linkers return true from
+ * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} for the type.
+ * @param type the type to link
+ * @return true if any of the composite linkers can link calls for the
+ * receiver type, false otherwise.
+ */
@Override
public boolean canLinkType(final Class<?> type) {
return !classToLinker.get(type).isEmpty();
@@ -180,17 +192,21 @@
}
/**
- * Optimizes a list of type-based linkers. If a group of adjacent linkers in the list all implement
- * {@link TypeBasedGuardingDynamicLinker}, they will be replaced with a single instance of
+ * Optimizes a list of type-based linkers. If a group of adjacent linkers in
+ * the list all implement {@link TypeBasedGuardingDynamicLinker}, they will
+ * be replaced with a single instance of
* {@link CompositeTypeBasedGuardingDynamicLinker} that contains them.
*
* @param linkers the list of linkers to optimize
* @return the optimized list
+ * @throws NullPointerException if {@code linkers} or any of its elements
+ * are null.
*/
public static List<GuardingDynamicLinker> optimize(final Iterable<? extends GuardingDynamicLinker> linkers) {
final List<GuardingDynamicLinker> llinkers = new LinkedList<>();
final List<TypeBasedGuardingDynamicLinker> tblinkers = new LinkedList<>();
for(final GuardingDynamicLinker linker: linkers) {
+ Objects.requireNonNull(linker);
if(linker instanceof TypeBasedGuardingDynamicLinker) {
tblinkers.add((TypeBasedGuardingDynamicLinker)linker);
} else {