From 9341bf3dc38b2cc117ffbe12ff057511ed6e046d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 16 Oct 2014 12:19:14 +0200 Subject: java: when rethrowing, store the original exception Change-Id: I34ce000c48d2d79bfec854c8dd55d12f2bee29c7 --- .../adapter/ByteArrayToXInputStreamAdapter.java | 10 ++-- .../star/lib/uno/helper/InterfaceContainer.java | 8 ++- .../com/sun/star/lib/uno/helper/PropertySet.java | 2 +- .../sun/star/lib/uno/helper/PropertySetMixin.java | 63 +++++++--------------- .../com/sun/star/lib/uno/helper/UnoUrl.java | 4 +- 5 files changed, 31 insertions(+), 56 deletions(-) (limited to 'javaunohelper') diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java index ecb1df66c296..19d5919383d8 100644 --- a/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java +++ b/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java @@ -87,12 +87,10 @@ public final class ByteArrayToXInputStreamAdapter System.arraycopy(m_bytes, m_pos, values[0], 0, param); m_pos += param; return param; - } catch (ArrayIndexOutOfBoundsException ae) { - ae.printStackTrace(); - throw new com.sun.star.io.BufferSizeExceededException("buffer overflow"); - } catch (Exception e) { - e.printStackTrace(); - throw new com.sun.star.io.IOException("error accessing buffer"); + } catch (ArrayIndexOutOfBoundsException ex) { + throw new com.sun.star.io.BufferSizeExceededException(ex, "buffer overflow"); + } catch (Exception ex) { + throw new com.sun.star.io.IOException(ex, "error accessing buffer"); } } diff --git a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java index 48ca6c68ab72..c867cad5d439 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java @@ -762,7 +762,9 @@ public class InterfaceContainer implements Cloneable } catch(java.lang.IndexOutOfBoundsException e) { - throw new java.util.NoSuchElementException(); + java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); + ex2.initCause(e); + throw ex2; } } @@ -828,7 +830,9 @@ public class InterfaceContainer implements Cloneable return previous; } catch(IndexOutOfBoundsException e) { - throw new NoSuchElementException(); + java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); + ex2.initCause(e); + throw ex2; } } diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java index aaf7691c123a..47407b1e78ad 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java @@ -167,7 +167,7 @@ XMultiPropertySet } catch (NoSuchFieldException e) { - throw new com.sun.star.uno.RuntimeException("there is no member variable: " + memberName); + throw new com.sun.star.uno.RuntimeException(e, "there is no member variable: " + memberName); } Class cl= propField.getType(); Type t= new Type(cl); diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java index b00519af7712..f3d9a8e907b2 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java @@ -135,9 +135,7 @@ public final class PropertySetMixin { + "theTypeDescriptionManager")). getByHierarchicalName(type.getTypeName()))); } catch (NoSuchElementException e) { - throw new RuntimeException( - "unexpected com.sun.star.container.NoSuchElementException: " - + e.getMessage()); + throw new RuntimeException(e); } HashMap map = new HashMap(); ArrayList handleNames = new ArrayList(); @@ -481,7 +479,7 @@ public final class PropertySetMixin { } catch (UnknownPropertyException e) { continue; } catch (WrappedTargetException e) { - throw new WrappedTargetRuntimeException( + throw new WrappedTargetRuntimeException(e, e.getMessage(), object, e.TargetException); } s[n++] = new PropertyValue(handleMap[i], i, value, state[0]); @@ -715,17 +713,15 @@ public final class PropertySetMixin { f.set(o, v); } catch (com.sun.star.lang.IllegalArgumentException e) { if (e.ArgumentPosition == 1) { - throw new com.sun.star.lang.IllegalArgumentException( + throw new com.sun.star.lang.IllegalArgumentException(e, e.getMessage(), object, illegalArgumentPosition); } else { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } } catch (com.sun.star.lang.IllegalAccessException e) { //TODO Clarify whether PropertyVetoException is the correct // exception to throw when trying to set a read-only property: - throw new PropertyVetoException( + throw new PropertyVetoException(e, "cannot set read-only property " + name, object); } catch (WrappedTargetRuntimeException e) { //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not @@ -736,14 +732,14 @@ public final class PropertySetMixin { AnyConverter.getType(e.TargetException)) && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) { - throw new UnknownPropertyException(name, object); + throw new UnknownPropertyException(e, name, object); } else if (new Type(PropertyVetoException.class).isSupertypeOf( AnyConverter.getType(e.TargetException)) && ((p.property.Attributes & PropertyAttribute.CONSTRAINED) != 0)) { - throw new PropertyVetoException(name, object); + throw new PropertyVetoException(e, name, object); } else { throw new WrappedTargetException( e.getMessage(), object, e.TargetException); @@ -765,9 +761,7 @@ public final class PropertySetMixin { value = field.get( new Any(type, UnoRuntime.queryInterface(type, object))); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } catch (WrappedTargetRuntimeException e) { //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not // guaranteed to originate directly within XIdlField2.get (and thus @@ -777,7 +771,7 @@ public final class PropertySetMixin { AnyConverter.getType(e.TargetException)) && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) { - throw new UnknownPropertyException(name, object); + throw new UnknownPropertyException(e, name, object); } else { throw new WrappedTargetException( e.getMessage(), object, e.TargetException); @@ -806,10 +800,7 @@ public final class PropertySetMixin { XIdlField2.class, ambiguous.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected" - + " com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } undoAmbiguous = false; } else if (undoDefaulted @@ -825,10 +816,7 @@ public final class PropertySetMixin { XIdlField2.class, defaulted.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected" - + " com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } undoDefaulted = false; } else if (undoOptional @@ -848,10 +836,7 @@ public final class PropertySetMixin { XIdlField2.class, optional.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected" - + " com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } undoOptional = false; } else { @@ -892,13 +877,9 @@ public final class PropertySetMixin { XIdlField2.class, type.getField("IsAmbiguous")).set( strct, Boolean.valueOf(isAmbiguous)); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalAccessException: " - + e.getMessage()); + throw new RuntimeException(e); } return strct[0]; } else if (wrapDefaulted @@ -919,13 +900,9 @@ public final class PropertySetMixin { XIdlField2.class, type.getField("IsDefaulted")).set( strct, Boolean.valueOf(isDefaulted)); } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalAccessException: " - + e.getMessage()); + throw new RuntimeException(e); } return strct[0]; } else if (wrapOptional @@ -948,13 +925,9 @@ public final class PropertySetMixin { wrapDefaulted, isDefaulted, false)); } } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalArgumentException: " - + e.getMessage()); + throw new RuntimeException(e); } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException( - "unexpected com.sun.star.lang.IllegalAccessException: " - + e.getMessage()); + throw new RuntimeException(e); } return strct[0]; } else { diff --git a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java b/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java index 23ab8022e17c..95d401440b3d 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java @@ -241,8 +241,8 @@ public class UnoUrl { } } catch (UnsupportedEncodingException e) { - throw new com.sun.star.lang.IllegalArgumentException( - "Couldn't convert parameter string to UTF-8 string:" + e.getMessage()); + throw new com.sun.star.lang.IllegalArgumentException(e, + "Couldn't convert parameter string to UTF-8 string"); } } -- cgit