Emulate Objects.requireNonNull() with message Supplier
Change-Id: Iec8c539a975e853e9f10089aa5a5034a29fe0607
diff --git a/tools/api-checker/config/gwt27_28userApi.conf b/tools/api-checker/config/gwt27_28userApi.conf
index ab2c219..5af2a09 100644
--- a/tools/api-checker/config/gwt27_28userApi.conf
+++ b/tools/api-checker/config/gwt27_28userApi.conf
@@ -176,3 +176,6 @@
# Legacy interop removed.
com.google.gwt.core.client.js MISSING
+
+# Added Objects.requireNonNull(Object, Supplier)
+java.util.Objects::requireNonNull(Ljava/lang/Object;Ljava/lang/String;) OVERLOADED_METHOD_CALL
diff --git a/user/super/com/google/gwt/emul/java/util/Objects.java b/user/super/com/google/gwt/emul/java/util/Objects.java
index 8780292..50cef14 100644
--- a/user/super/com/google/gwt/emul/java/util/Objects.java
+++ b/user/super/com/google/gwt/emul/java/util/Objects.java
@@ -15,6 +15,8 @@
*/
package java.util;
+import java.util.function.Supplier;
+
/**
* See <a
* href="http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html">the
@@ -114,6 +116,13 @@
return obj;
}
+ public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) {
+ if (obj == null) {
+ throw new NullPointerException(messageSupplier.get());
+ }
+ return obj;
+ }
+
public static String toString(Object o) {
return String.valueOf(o);
}