public static void arraycopy(ByteBuffer src, int srcPos, ByteBuffer dest, int destPos, int length) { if (length < 0) throw new IndexOutOfBoundsException("length must be >= 0. (length = " + length + ")"); if (srcPos < 0) throw new IndexOutOfBoundsException("srcPos must be >= 0. (srcPos = " + srcPos + ")"); if (destPos < 0) throw new IndexOutOfBoundsException("destPos must be >= 0. (destPos = " + destPos + ")"); if (srcPos + length > src.capacity()) throw new IndexOutOfBoundsException("srcPos + length must be <= src.capacity(). (srcPos = " + srcPos + ", length = " + length + ", capacity = " + src.capacity() + ")"); if (destPos + length > dest.capacity()) throw new IndexOutOfBoundsException("destPos + length must be <= dest.capacity(). (destPos = " + destPos + ", length = " + length + ", capacity = " + dest.capacity() + ")"); if (SUPPORTED) { copy(src, srcPos, dest, destPos, length); } else { UnsafeTools.getUnsafe().copyMemory(address(src) + srcPos, address(dest) + destPos, length); } }
private void switchUnsafe(boolean enabled) throws NoSuchFieldException, IllegalAccessException { Field field = FieldReflectionFactory.class.getDeclaredField("unsafe"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setAccessible(true); field.set(null, enabled ? UnsafeTools.getUnsafe() : null); } }
@Test public void test_parameter_has_name() throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException { Constructor<java.lang.reflect.Parameter> parameterConstructor = (Constructor<java.lang.reflect.Parameter>) java.lang.reflect.Parameter.class.getDeclaredConstructors()[0]; parameterConstructor.setAccessible(true); Method method = (Method) UnsafeTools.getUnsafe().allocateInstance(Method.class); java.lang.reflect.Parameter parameter = parameterConstructor.newInstance("fieldName", 0, method, 0); new FieldReflectionFactory().create(Executable.class, "hasRealParameterData", true).setBoolean(method, true); new FieldReflectionFactory().create(Executable.class, "parameters", true).setObject(method, Array.newInstance(java.lang.reflect.Parameter.class, 1)); Assert.assertEquals("fieldName", ParametersHelper.getParameterName(parameter)); }