From 2ede696737093cfa2c24bcc912c7d1195cfc832e Mon Sep 17 00:00:00 2001 From: Kyle Feuz Date: Wed, 16 Apr 2014 21:08:08 -0700 Subject: [PATCH] Fixed splice() ClassCastException issue 1445 --- core/src/processing/core/PApplet.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 8de399ccc..5a1e47ee9 100755 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -8606,19 +8606,20 @@ public class PApplet extends Applet } static final public Object splice(Object list, Object value, int index) { - Object[] outgoing = null; + Class type = list.getClass().getComponentType(); + Object outgoing = null; int length = Array.getLength(list); // check whether item being spliced in is an array if (value.getClass().getName().charAt(0) == '[') { int vlength = Array.getLength(value); - outgoing = new Object[length + vlength]; + outgoing = Array.newInstance(type, length + vlength); System.arraycopy(list, 0, outgoing, 0, index); System.arraycopy(value, 0, outgoing, index, vlength); System.arraycopy(list, index, outgoing, index + vlength, length - index); } else { - outgoing = new Object[length + 1]; + outgoing = Array.newInstance(type, length + 1); System.arraycopy(list, 0, outgoing, 0, index); Array.set(outgoing, index, value); System.arraycopy(list, index, outgoing, index + 1, length - index);