Refine search
public Object fromString(String str) { try { return ctor.newInstance(new Object[] {str}); } catch (InstantiationException e) { throw new ConversionException("Unable to instantiate single String param constructor", e); } catch (IllegalAccessException e) { throw new ObjectAccessException("Unable to access single String param constructor", e); } catch (InvocationTargetException e) { throw new ConversionException("Unable to target single String param constructor", e.getTargetException()); } } }
: createNullArguments(parameterTypes)); } catch (IllegalAccessException e) { ObjectAccessException exception = new ObjectAccessException("Cannot access method", e); exception.add("method", calledMethod.toString()); throw exception; } catch (InvocationTargetException e) { ConversionException exception = new ConversionException( "CGLIB enhanced proxies wit abstract nethod that has not been implemented"); exception.add("proxy-superclass", type.getSuperclass().getName()); exception.add("method", method.toString()); throw exception;
private static ObjectAccessException wrap(final String message, final Class type, final String name, final Throwable ex) { final ObjectAccessException exception = new ObjectAccessException(message, ex); exception.add("field", type.getName() + "." + name); return exception; } }
public Object newInstance(Class type) { if (exception != null) { ObjectAccessException ex = new ObjectAccessException("Cannot construct type", exception); ex.add("construction-type", type.getName()); throw ex; } ErrorWritingException ex = null; if (type == void.class || type == Void.class) { ex = new ConversionException("Type void cannot have an instance"); } else { try { return unsafe.allocateInstance(type); } catch (final SecurityException e) { ex = new ObjectAccessException("Cannot construct type", e); } catch (final InstantiationException e) { ex = new ConversionException("Cannot construct type", e); } catch (final IllegalArgumentException e) { ex = new ObjectAccessException("Cannot construct type", e); } } ex.add("construction-type", type.getName()); throw ex; }
public Object clone() { try { XmlFriendlyNameCoder coder = (XmlFriendlyNameCoder)super.clone(); coder.readResolve(); return coder; } catch (CloneNotSupportedException e) { throw new ObjectAccessException("Cannot clone XmlFriendlyNameCoder", e); } }
protected void validateFieldAccess(Field field) { if (Modifier.isFinal(field.getModifiers())) { if (JVM.isVersion(5)) { if (!field.isAccessible()) { field.setAccessible(true); } } else { throw new ObjectAccessException("Invalid final field " + field.getDeclaringClass().getName() + "." + field.getName()); } } }
return instantiateUsingSerialization(type); } else { oaex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor"); oaex = new ObjectAccessException("Cannot construct type", e); } catch (IllegalAccessException e) { oaex = new ObjectAccessException("Cannot construct type", e); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof RuntimeException) { throw (Error)e.getTargetException(); } else { oaex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException()); oaex.add("construction-type", type.getName()); throw oaex;
public Object newInstance() { ErrorWritingException ex = null; try { return editorType.newInstance(); } catch (InstantiationException e) { ex = new ConversionException("Faild to call default constructor", e); } catch (IllegalAccessException e) { ex = new ObjectAccessException("Cannot call default constructor", e); } ex.add("construction-type", editorType.getName()); throw ex; }
callbackIndexMap = createCallbackIndexMap((Factory)source); } else { ConversionException exception = new ConversionException( "Cannot handle CGLIB enhanced proxies without factory that have multiple callbacks"); exception.add("proxy-superclass", type.getSuperclass().getName()); exception.add("number-of-callbacks", String.valueOf(callbacks.length)); throw exception; ObjectAccessException exception = new ObjectAccessException("Cannot access field", e); exception.add("field", type.getName() + ".serialVersionUID"); throw exception;
/** * Instantiates a converter using its default constructor. * * @param type the converter type to instantiate * @return the new instance */ private Converter newInstance(Class<? extends ConverterMatcher> type) { Converter converter; // TODO: We need a separate exception for runtime initialization. try { if (SingleValueConverter.class.isAssignableFrom(type)) { final SingleValueConverter svc = (SingleValueConverter)type.getConstructor().newInstance(); converter = new SingleValueConverterWrapper(svc); } else { converter = (Converter)type.getConstructor().newInstance(); } } catch (InvocationTargetException e) { throw new ObjectAccessException("Cannot construct " + type.getName(), e .getCause()); } catch (InstantiationException e) { throw new ObjectAccessException("Cannot construct " + type.getName(), e); } catch (IllegalAccessException e) { throw new ObjectAccessException("Cannot construct " + type.getName(), e); } catch (NoSuchMethodException e) { throw new ObjectAccessException("Cannot construct " + type.getName(), e); } return converter; }
private Map buildMap(Class type) { Map nameMap = (Map)propertyNameCache.get(type); if (nameMap == null) { BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(type, Object.class); } catch (IntrospectionException e) { ObjectAccessException oaex = new ObjectAccessException("Cannot get BeanInfo of type", e); oaex.add("bean-type", type.getName()); throw oaex; } nameMap = new OrderRetainingMap(); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (int i = 0; i < propertyDescriptors.length; i++ ) { PropertyDescriptor descriptor = propertyDescriptors[i]; nameMap.put(descriptor.getName(), descriptor); } nameMap = sorter.sort(type, nameMap); propertyNameCache.put(type, nameMap); } return nameMap; }
public Object newInstance(Class type) { ErrorWritingException ex = null; try { return type.newInstance(); } catch (InstantiationException e) { ex = new ConversionException("Cannot construct type", e); } catch (IllegalAccessException e) { ex = new ObjectAccessException("Cannot construct type", e); } catch (SecurityException e) { ex = new ObjectAccessException("Cannot construct type", e); } catch (ExceptionInInitializerError e) { ex = new ConversionException("Cannot construct type", e); } ex.add("construction-type", type.getName()); throw ex; }
public static Object clone(Object o) { if (o instanceof Cloneable) { if (o.getClass().isArray()) { final Class componentType = o.getClass().getComponentType(); if (!componentType.isPrimitive()) { return ((Object[])o).clone(); } else { int length = Array.getLength(o); final Object clone = Array.newInstance(componentType, length); while (length-- > 0) { Array.set(clone, length, Array.get(o, length)); } return clone; } } else { try { Method clone = o.getClass().getMethod("clone", (Class[])null); return clone.invoke(o, (Object[])null); } catch (NoSuchMethodException e) { throw new ObjectAccessException("Cloneable type has no clone method", e); } catch (IllegalAccessException e) { throw new ObjectAccessException("Cannot clone Cloneable type", e); } catch (InvocationTargetException e) { throw new ObjectAccessException("Exception cloning Cloneable type", e.getCause()); } } } return null; }
list.add(callback); } catch (IllegalAccessException e) { ObjectAccessException exception = new ObjectAccessException("Cannot access field", e); exception.add("field", type.getName() + "." + CALLBACK_MARKER + i); throw exception;
public void writeProperty(Object object, String propertyName, Object value) { ErrorWritingException ex = null; PropertyDescriptor property = getProperty(propertyName, object.getClass()); try { property.getWriteMethod().invoke(object, new Object[]{value}); } catch (IllegalArgumentException e) { ex = new ConversionException("Cannot set property", e); } catch (IllegalAccessException e) { ex = new ObjectAccessException("Cannot access property", e); } catch (InvocationTargetException e) { ex = new ConversionException("Cannot set property", e.getTargetException()); } if (ex != null) { ex.add("property", object.getClass() + "." + property.getName()); throw ex; } }
private Map writeValueToImplicitCollection(UnmarshallingContext context, Object value, Map implicitCollections, Object result, String itemFieldName) { String fieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value.getClass(), itemFieldName); if (fieldName != null) { if (implicitCollections == null) { implicitCollections = new HashMap(); // lazy instantiation } Collection collection = (Collection) implicitCollections.get(fieldName); if (collection == null) { Class fieldType = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, null)); if (!Collection.class.isAssignableFrom(fieldType)) { throw new ObjectAccessException("Field " + fieldName + " of " + result.getClass().getName() + " is configured for an implicit Collection, but field is of type " + fieldType.getName()); } if (pureJavaReflectionProvider == null) { pureJavaReflectionProvider = new PureJavaReflectionProvider(); } collection = (Collection)pureJavaReflectionProvider.newInstance(fieldType); reflectionProvider.writeField(result, fieldName, collection, null); implicitCollections.put(fieldName, collection); } collection.add(value); } return implicitCollections; }
oaex = new ObjectAccessException("Cannot create type by JDK serialization", e); } catch (ClassNotFoundException e) { oaex = new ObjectAccessException("Cannot find class", e); oaex.add("construction-type", type.getName()); throw oaex;
public void callWriteObject(final Class type, final Object instance, final ObjectOutputStream stream) { ErrorWritingException ex = null; try { Method readObjectMethod = getMethod( type, "writeObject", new Class[]{ObjectOutputStream.class}, false); readObjectMethod.invoke(instance, new Object[]{stream}); } catch (IllegalAccessException e) { ex = new ObjectAccessException("Cannot access method", e); } catch (InvocationTargetException e) { ex = new ConversionException("Failed calling method", e.getTargetException()); } if (ex != null) { ex.add("method", instance.getClass().getName() + ".writeObject()"); throw ex; } }
/** * Create the DocumentBuilderFactory instance. * * @return the new instance * @since 1.4.9 */ protected DocumentBuilderFactory createDocumentBuilderFactory() { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); if (JVM.isVersion(5)) { try { Method method = DocumentBuilderFactory.class.getMethod("setFeature", new Class[]{ String.class, boolean.class }); method.invoke(factory, new Object[]{ "http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE }); } catch (NoSuchMethodException e) { // Ignore } catch (IllegalAccessException e) { throw new ObjectAccessException("Cannot set feature of DocumentBuilderFactory.", e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (JVM.isVersion(6) || (cause instanceof ParserConfigurationException && cause.getMessage().indexOf("disallow-doctype-decl") < 0)) { throw new StreamException(cause); } } } factory.setExpandEntityReferences(false); return factory; } }
private void write(Field field, Object object, Object value) { if (exception != null) { ObjectAccessException ex = new ObjectAccessException("Cannot set field", exception); ex.add("field", object.getClass() + "." + field.getName()); throw ex; unsafe.putBoolean(object, offset, ((Boolean)value).booleanValue()); } else { ObjectAccessException ex = new ObjectAccessException("Cannot set field of unknown type", exception); ex.add("field", object.getClass() + "." + field.getName()); ex.add("unknown-type", type.getName()); throw ex; ObjectAccessException ex = new ObjectAccessException("Cannot set field", e); ex.add("field", object.getClass() + "." + field.getName()); throw ex;