private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) { if (colors == null) { throw new NullPointerException("colors"); } try (CFMutableArray colorsArray = CFMutableArray.createMutable(null, colors.length, CoreFoundation.TypeArrayCallBacks())) { for (CGColor c : colors) { colorsArray.appendValue(Struct.toStruct(VoidPtr.class, c.getHandle())); } return create( space, colorsArray, locations != null ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations)) : 0); } }