protected final void write(final Marshaller marshaller) throws IOException { final FieldPutter[] fields = this.fields; final int len = fields.length; for (int i = 0; i < len; i++) try { fields[i].write(marshaller); } catch (IOException e) { TraceInformation.addFieldInformation(e, names[i]); throw e; } catch (RuntimeException e) { TraceInformation.addFieldInformation(e, names[i]); throw e; } } }
/** * Add information about an incomplete object which was being unmarshalled. * * @param t the throwable to update * @param targetClass the class of the target object being unmarshalled */ public static void addIncompleteObjectInformation(Throwable t, Class<?> targetClass) { addIncompleteObjectInformation(t, getNiceClassName(targetClass)); }
Object doReadCollectionObject(final boolean unshared, final int idx, final int size, final boolean discardMissing) throws ClassNotFoundException, IOException { try { return doReadObject(unshared, discardMissing); } catch (IOException e) { TraceInformation.addIndexInformation(e, idx, size, TraceInformation.IndexType.ELEMENT); throw e; } catch (ClassNotFoundException e) { TraceInformation.addIndexInformation(e, idx, size, TraceInformation.IndexType.ELEMENT); throw e; } catch (RuntimeException e) { TraceInformation.addIndexInformation(e, idx, size, TraceInformation.IndexType.ELEMENT); throw e; } }
/** * Add information about an object which was being (un-)marshalled. * * @param t the throwable to update * @param targetObject the target object which was being (un-)marshalled */ public static void addObjectInformation(Throwable t, Object targetObject) { final TraceInformation ti = getOrAddTraceInformation(t); final String targetClassName = getNiceClassName(targetObject.getClass()); int targetHashCode = 0; try { targetHashCode = targetObject.hashCode(); } catch (Throwable ignored) { // guess we won't know the hash code! } final Info oldInfo = ti.info; ti.info = new ObjectInfo(oldInfo, targetClassName, targetHashCode); }
TraceInformation.addFieldInformation(e, info, serializableField); TraceInformation.addObjectInformation(e, obj); throw e;
Object doReadNestedObject(final boolean unshared, final String enclosingClassName) throws ClassNotFoundException, IOException { try { return doReadObject(unshared); } catch (IOException e) { TraceInformation.addIncompleteObjectInformation(e, enclosingClassName); throw e; } catch (ClassNotFoundException e) { TraceInformation.addIncompleteObjectInformation(e, enclosingClassName); throw e; } catch (RuntimeException e) { TraceInformation.addIncompleteObjectInformation(e, enclosingClassName); throw e; } }
/** {@inheritDoc} */ public final void writeObjectUnshared(final Object obj) throws IOException { try { super.writeObjectUnshared(obj); } catch (IOException e) { TraceInformation.addObjectInformation(e, obj); exceptionListener.handleMarshallingException(e, obj); throw e; } catch (RuntimeException e) { TraceInformation.addObjectInformation(e, obj); exceptionListener.handleMarshallingException(e, obj); throw e; } }
/** * Add user information about problem with marshalling or unmarshalling. * * @param t the throwable to update * @param data the user data */ public static void addUserInformation(Throwable t, Serializable data) { final TraceInformation ti = getOrAddTraceInformation(t); final Info oldInfo = ti.info; ti.info = new UserInfo(oldInfo, data); }
private static String getNiceClassName(Class<?> clazz) { if (clazz == null) { return "unknown class"; } else if (clazz.isArray()) { return "(array of " + getNiceClassName(clazz.getComponentType()) + ")"; } else if (clazz.isEnum() && clazz.getSuperclass() != Enum.class) { return getNiceClassName(clazz.getSuperclass()); } else { return clazz.getName(); } }
private static TraceInformation getOrAddTraceInformation(Throwable t) { if (t == null) { throw new NullPointerException("t is null"); } Throwable c; while (! (t instanceof TraceInformation)) { c = t.getCause(); if (c == null) try { t.initCause(c = new TraceInformation()); } catch (RuntimeException e) { // ignored } t = c; } return (TraceInformation) t; }
TraceInformation.addFieldInformation(e, descriptor.getSerializableClass(), serializableField); TraceInformation.addObjectInformation(e, obj); throw e;
TraceInformation.addIncompleteObjectInformation(e, descriptor.getType()); exceptionListener.handleUnmarshallingException(e, descriptor.getType()); throw e; } catch (ClassNotFoundException e) { TraceInformation.addIncompleteObjectInformation(e, descriptor.getType()); exceptionListener.handleUnmarshallingException(e, descriptor.getType()); throw e; } catch (RuntimeException e) { TraceInformation.addIncompleteObjectInformation(e, descriptor.getType()); exceptionListener.handleUnmarshallingException(e, descriptor.getType()); throw e;
/** * Add information about an object which was being (un-)marshalled. * * @param t the throwable to update * @param targetObject the target object which was being (un-)marshalled */ public static void addObjectInformation(Throwable t, Object targetObject) { final TraceInformation ti = getOrAddTraceInformation(t); final String targetClassName = getNiceClassName(targetObject.getClass()); int targetHashCode = 0; try { targetHashCode = targetObject.hashCode(); } catch (Throwable ignored) { // guess we won't know the hash code! } final Info oldInfo = ti.info; ti.info = new ObjectInfo(oldInfo, targetClassName, targetHashCode); }
/** {@inheritDoc} */ public final void writeObject(final Object obj) throws IOException { try { super.writeObject(obj); } catch (IOException e) { TraceInformation.addObjectInformation(e, obj); exceptionListener.handleMarshallingException(e, obj); throw e; } catch (RuntimeException e) { TraceInformation.addObjectInformation(e, obj); exceptionListener.handleMarshallingException(e, obj); throw e; } }
/** * Add information about an incomplete object which was being unmarshalled. * * @param t the throwable to update * @param targetClassName the class of the target object being unmarshalled */ public static void addIncompleteObjectInformation(Throwable t, String targetClassName) { final TraceInformation ti = getOrAddTraceInformation(t); final Info oldInfo = ti.info; ti.info = new IncompleteObjectInfo(oldInfo, targetClassName); }
private static String getNiceClassName(Class<?> clazz) { if (clazz == null) { return "unknown class"; } else if (clazz.isArray()) { return "(array of " + getNiceClassName(clazz.getComponentType()) + ")"; } else if (clazz.isEnum() && clazz.getSuperclass() != Enum.class) { return getNiceClassName(clazz.getSuperclass()); } else { return clazz.getName(); } }
private static TraceInformation getOrAddTraceInformation(Throwable t) { if (t == null) { throw new NullPointerException("t is null"); } Throwable c; while (! (t instanceof TraceInformation)) { c = t.getCause(); if (c == null) try { t.initCause(c = new TraceInformation()); } catch (RuntimeException e) { // ignored } t = c; } return (TraceInformation) t; }
TraceInformation.addFieldInformation(e, info, serializableField); TraceInformation.addObjectInformation(e, obj); throw e;
/** * Add information about an incomplete object which was being unmarshalled. * * @param t the throwable to update * @param targetClass the class of the target object being unmarshalled */ public static void addIncompleteObjectInformation(Throwable t, Class<?> targetClass) { addIncompleteObjectInformation(t, getNiceClassName(targetClass)); }
/** * Add information about a field which was being marshalled. * * @param t the throwable to update * @param owner * Reference to the class that owns the field. * @param field * The field being (un-)marshalled. */ public static void addFieldInformation(Throwable t, SerializableClass owner, SerializableField field) { addFieldInformation(t,owner.getSubjectClass().getName()+"."+field.getName()); }