in xstream/src/java/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java [67:100]
public Object newInstance(final Class<?> type) {
ErrorWritingException ex = null;
if (type == void.class || type == Void.class) {
ex = new ConversionException("Security alert: Marshalling rejected");
} else {
try {
for (final Constructor<?> constructor : type.getDeclaredConstructors()) {
if (constructor.getParameterTypes().length == 0) {
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
return constructor.newInstance(new Object[0]);
}
}
if (Serializable.class.isAssignableFrom(type)) {
return instantiateUsingSerialization(type);
} else {
ex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
}
} catch (final InstantiationException | IllegalAccessException e) {
ex = new ObjectAccessException("Cannot construct type", e);
} catch (final InvocationTargetException e) {
if (e.getTargetException() instanceof RuntimeException) {
throw (RuntimeException)e.getTargetException();
} else if (e.getTargetException() instanceof Error) {
throw (Error)e.getTargetException();
} else {
ex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException());
}
}
}
ex.add("construction-type", type.getName());
throw ex;
}