ArrayAccessor extends ArrayPropertyAccessor { @Override public void setProperty(Map context, Object array, Object key, Object value) throws OgnlException { int index = (Integer) key; int length = Array.getLength(array); if (length <= index) { Object newArray = copyOf(array, index, length); OgnlContext ctx = (OgnlContext) context; if (array == ctx.getRoot()) { ctx.setRoot(newArray); } else { String fieldName = ctx.getCurrentEvaluation().getPrevious().getNode().toString(); Object origin = ctx.getCurrentEvaluation().getPrevious().getSource(); Proxifier proxifier = (Proxifier) context.get("proxifier"); Method setter = new ReflectionBasedNullHandler(proxifier).findMethod(origin.getClass(), "set" + StringUtils.capitalize(fieldName), origin.getClass(), null); EmptyElementsRemoval removal = (EmptyElementsRemoval) context.get("removal"); removal.add(newArray, setter, origin); new Mirror().on(origin).invoke().method(setter).withArgs(newArray); } array = newArray; } super.setProperty(context, array, key, value); }  @Override Object getProperty(Map context, Object target, Object object); @Override void setProperty(Map context, Object array, Object key, Object value);  }
@Test @Ignore("Mocks with mockito don't work") public void settingShouldNullifyUpToIndexAndIgnoreRemoval() throws Exception { final Long[] l = new Long[] {}; when(context.getRoot()).thenReturn(instance); when(typeConverter.convertValue(anyMap(), any(), (Member) any(Member.class), anyString(), any(), any(Class.class))).thenReturn(22L); accessor.setProperty(context, l, 1, 22L); assertThat(instance.simpleNode[0], is(nullValue())); assertThat(instance.simpleNode[1], is(equalTo(22L))); }