diff truffle/com.oracle.truffle.api.interop.java/src/com/oracle/truffle/api/interop/java/JavaInterop.java @ 22279:0fc995134ff3

asJavaObject can work with null value
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Tue, 06 Oct 2015 13:27:47 +0200
parents 364e3f024643
children df98dd526dd4
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.interop.java/src/com/oracle/truffle/api/interop/java/JavaInterop.java	Tue Oct 06 13:08:12 2015 +0200
+++ b/truffle/com.oracle.truffle.api.interop.java/src/com/oracle/truffle/api/interop/java/JavaInterop.java	Tue Oct 06 13:27:47 2015 +0200
@@ -135,9 +135,12 @@
      *
      * @param <T> type of requested and returned value
      * @param type interface modeling structure of <code>foreignObject</code> in <b>Java</b>
-     * @param foreignObject object coming from a {@link TruffleObject Truffle language}
+     * @param foreignObject object coming from a {@link TruffleObject Truffle language}, can be
+     *            <code>null</code>, in such case the returned value will likely be
+     *            <code>null</code> as well
      * @return instance of requested interface granting access to specified
-     *         <code>foreignObject</code>
+     *         <code>foreignObject</code>, can be <code>null</code>, if the foreignObject parameter
+     *         was <code>null</code>
      */
     public static <T> T asJavaObject(Class<T> type, TruffleObject foreignObject) {
         return asJavaObject(type, null, foreignObject);
@@ -151,6 +154,9 @@
             if (!clazz.isInterface()) {
                 throw new IllegalArgumentException();
             }
+            if (foreignObject == null) {
+                return null;
+            }
             if (clazz == List.class && Boolean.TRUE.equals(message(Message.HAS_SIZE, foreignObject))) {
                 Class<?> elementType = Object.class;
                 if (type instanceof ParameterizedType) {