From 6d6143043c4758c68bb570211910625a7a92070e Mon Sep 17 00:00:00 2001
From: stepan <stepan.sindelar@oracle.com>
Date: Tue, 23 May 2017 10:03:24 +0200
Subject: [PATCH] FastR Grid: more robust/tolerant color format.

---
 .../com/oracle/truffle/r/library/fastrGrid/GPar.java  | 11 ++++++++++-
 .../truffle/r/library/fastrGrid/GridColorUtils.java   |  6 +++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java
index f826ccd696..2e46872077 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java
@@ -264,7 +264,16 @@ public final class GPar {
         }
 
         private GridColor getGridColor(int listIndex) {
-            GridColor color = GridColorUtils.gridColorFromString(GridUtils.asString(data[listIndex], index));
+            Object value = data[listIndex];
+            String strValue = null;
+            if (value instanceof String) {
+                strValue = (String) value;
+            } else if (value instanceof RAbstractStringVector && ((RAbstractStringVector) value).getLength() > 0) {
+                strValue = ((RAbstractStringVector) value).getDataAt(listIndex % ((RAbstractStringVector) value).getLength());
+            } else {
+                return GridColor.TRANSPARENT;
+            }
+            GridColor color = GridColorUtils.gridColorFromString(strValue);
             double alpha = asDouble(data[GP_ALPHA], index);
             if (alpha != 1.) {
                 int newAlpha = Math.min(255, (int) (alpha * ((color.getAlpha() / 255.0) * 255)));
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridColorUtils.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridColorUtils.java
index 939a90546e..9ab71e8923 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridColorUtils.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridColorUtils.java
@@ -34,6 +34,11 @@ public final class GridColorUtils {
             return parseHex(value);
         }
 
+        if (value.equals("NA")) {
+            // special case value, we want to check only for "NA", not "na".
+            return GridColor.TRANSPARENT;
+        }
+
         Object result = findByName(value);
         if (result == null) {
             throw RError.error(RError.NO_CALLER, Message.GENERIC, "Invalid color '" + value + "'.");
@@ -84,7 +89,6 @@ public final class GridColorUtils {
 
         static {
             NAMES.put("transparent", GridColor.TRANSPARENT);
-            NAMES.put("NA", GridColor.TRANSPARENT);
             NAMES.put("white", "#FFFFFF");
             NAMES.put("aliceblue", "#F0F8FF");
             NAMES.put("antiquewhite", "#FAEBD7");
-- 
GitLab