Skip to content

Commit

Permalink
Join catch using multicatch. Closes #167.
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur authored and joehni committed Aug 2, 2020
1 parent b678bd7 commit 470f1cb
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 201 deletions.
8 changes: 2 additions & 6 deletions xstream/src/java/com/thoughtworks/xstream/XStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,7 @@ private Mapper buildMapperDynamically(final String className, final Class<?>[] c
final Class<?> type = Class.forName(className, false, classLoaderReference.getReference());
final Constructor<?> constructor = type.getConstructor(constructorParamTypes);
return (Mapper)constructor.newInstance(constructorParamValues);
} catch (final Exception e) {
throw new InitializationException("Could not instantiate mapper : " + className, e);
} catch (final LinkageError e) {
} catch (final Exception | LinkageError e) {
throw new InitializationException("Could not instantiate mapper : " + className, e);
}
}
Expand Down Expand Up @@ -1009,9 +1007,7 @@ private void registerConverterDynamically(final String className, final int prio
} else if (instance instanceof SingleValueConverter) {
registerConverter((SingleValueConverter)instance, priority);
}
} catch (final Exception e) {
throw new InitializationException("Could not instantiate converter : " + className, e);
} catch (final LinkageError e) {
} catch (final Exception | LinkageError e) {
throw new InitializationException("Could not instantiate converter : " + className, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 XStream Committers.
* Copyright (C) 2015, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -87,9 +87,7 @@ public Object unmarshal(final HierarchicalStreamReader reader, final Unmarshalli
} else {
dataFlavor = new ActivationDataFlavor(type, mimeType, name);
}
} catch (final IllegalArgumentException ex) {
throw new ConversionException(ex);
} catch (final NullPointerException ex) {
} catch (final IllegalArgumentException | NullPointerException ex) {
throw new ConversionException(ex);
}
return dataFlavor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004 Joe Walnes.
* Copyright (C) 2006, 2007, 2014, 2018, 2019 XStream Committers.
* Copyright (C) 2006, 2007, 2014, 2018, 2019, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -89,13 +89,7 @@ StackTraceElement create(final String classLoaderName, final String moduleName,
return constructor
.newInstance(classLoaderName, moduleName, moduleVersion, declaringClass, methodName, fileName,
lineNumber);
} catch (final NoSuchMethodException e) {
ex = e;
} catch (final InstantiationException e) {
ex = e;
} catch (final IllegalAccessException e) {
ex = e;
} catch (final InvocationTargetException e) {
} catch (final NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
ex = e;
}
if (ex != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -66,14 +66,12 @@ public Object newInstance(final Class<?> type) {
ErrorWritingException ex = null;
try {
return type.newInstance();
} catch (final InstantiationException e) {
} catch (final InstantiationException | ExceptionInInitializerError e) {
ex = new ConversionException("Cannot construct type", e);
} catch (final IllegalAccessException e) {
ex = new ObjectAccessException("Cannot construct type", e);
} catch (final SecurityException e) {
ex = new ObjectAccessException("Cannot construct type", e);
} catch (final ExceptionInInitializerError e) {
ex = new ConversionException("Cannot construct type", e);
}
ex.add("construction-type", type.getName());
throw ex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016, 2018, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -195,16 +195,12 @@ public void close() {
return serializationMembers.callReadResolve(externalizable);
} catch (final NoSuchMethodException e) {
throw new ConversionException("Missing default constructor of type", e);
} catch (final InvocationTargetException e) {
throw new ConversionException("Cannot construct type", e);
} catch (final InstantiationException e) {
} catch (final InvocationTargetException | InstantiationException | ClassNotFoundException e) {
throw new ConversionException("Cannot construct type", e);
} catch (final IllegalAccessException e) {
throw new ObjectAccessException("Cannot construct type", e);
} catch (final IOException e) {
throw new StreamException("Cannot externalize " + type.getClass(), e);
} catch (final ClassNotFoundException e) {
throw new ConversionException("Cannot construct type", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014, 2015, 2016 XStream Committers.
* Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014, 2015, 2016, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -76,9 +76,7 @@ public Object newInstance(final Class<?> type) {
} else {
oaex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
}
} catch (final InstantiationException e) {
oaex = new ObjectAccessException("Cannot construct type", e);
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException e) {
oaex = new ObjectAccessException("Cannot construct type", e);
} catch (final InvocationTargetException e) {
if (e.getTargetException() instanceof RuntimeException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017, 2020 XStream Committers.
* All rights reserved.
*
* Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProvider
Expand Down Expand Up @@ -45,13 +45,7 @@ public class SunLimitedUnsafeReflectionProvider extends PureJavaReflectionProvid
final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
u = (Unsafe)unsafeField.get(null);
} catch (final SecurityException e) {
ex = e;
} catch (final NoSuchFieldException e) {
ex = e;
} catch (final IllegalArgumentException e) {
ex = e;
} catch (final IllegalAccessException e) {
} catch (final SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
ex = e;
}
exception = ex;
Expand Down Expand Up @@ -85,12 +79,10 @@ public Object newInstance(final Class<?> type) {
} else {
try {
return unsafe.allocateInstance(type);
} catch (final SecurityException e) {
} catch (final SecurityException | IllegalArgumentException 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());
Expand Down
20 changes: 5 additions & 15 deletions xstream/src/java/com/thoughtworks/xstream/core/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ static class Test {
final Method allocateInstance = unsafeClass.getDeclaredMethod("allocateInstance", new Class[]{Class.class});
allocateInstance.setAccessible(true);
test = allocateInstance.invoke(unsafe, new Object[]{Test.class}) != null;
} catch (final Exception e) {
test = false;
} catch (final Error e) {
} catch (final Exception | Error e) {
test = false;
}
canAllocateWithUnsafe = test;
Expand All @@ -128,9 +126,7 @@ static class Test {
provider.writeField(t, "d", Double.valueOf(1), Test.class);
provider.writeField(t, "bool", Boolean.TRUE, Test.class);
test = true;
} catch (final IncompatibleClassChangeError e) {
cls = null;
} catch (final ObjectAccessException e) {
} catch (final IncompatibleClassChangeError | ObjectAccessException e) {
cls = null;
}
if (cls == null) {
Expand Down Expand Up @@ -179,19 +175,15 @@ public int compare(final Object o1, final Object o2) {
try {
new SimpleDateFormat("X").parse("Z");
test = true;
} catch (final ParseException e) {
test = false;
} catch (final IllegalArgumentException e) {
} catch (final ParseException | IllegalArgumentException e) {
test = false;
}
canParseISO8601TimeZoneInDateFormat = test;
try {
@SuppressWarnings("resource")
final CustomObjectOutputStream stream = new CustomObjectOutputStream(null, null);
test = stream != null;
} catch (final RuntimeException e) {
test = false;
} catch (final IOException e) {
} catch (final RuntimeException | IOException e) {
test = false;
}
canCreateDerivedObjectOutputStream = test;
Expand Down Expand Up @@ -344,9 +336,7 @@ public static <T> Class<? extends T> loadClassForName(final String name, final b
final Class<? extends T> clazz = (Class<? extends T>)Class
.forName(name, initialize, JVM.class.getClassLoader());
return clazz;
} catch (final LinkageError e) {
return null;
} catch (final ClassNotFoundException e) {
} catch (final LinkageError | ClassNotFoundException e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers.
* Copyright (c) 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -251,16 +251,10 @@ public int compare(final Constructor<?> o1, final Constructor<?> o2) {
}

return instance;
} catch (final InstantiationException e) {
th = e;
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException | SecurityException | ExceptionInInitializerError e) {
th = e;
} catch (final InvocationTargetException e) {
th = e.getCause();
} catch (final SecurityException e) {
th = e;
} catch (final ExceptionInInitializerError e) {
th = e;
}
final ObjectAccessException ex = new ObjectAccessException("Cannot construct type", th);
ex.add("construction-type", type.getName());
Expand Down
29 changes: 6 additions & 23 deletions xstream/src/java/com/thoughtworks/xstream/core/util/Fields.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014, 2016, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014, 2016, 2018, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -39,11 +39,10 @@ public static Field locate(final Class<?> definedIn, final Class<?> fieldType, f
if (field != null && !field.isAccessible()) {
field.setAccessible(true);
}
} catch (final SecurityException e) {
} catch (final SecurityException | NoClassDefFoundError e) {
// active SecurityManager
} catch (final NoClassDefFoundError e) {
// restricted type in GAE
}
// restricted type in GAE
return field;
}

Expand All @@ -54,39 +53,23 @@ public static Field find(final Class<?> type, final String name) {
result.setAccessible(true);
}
return result;
} catch (final SecurityException e) {
throw wrap("Cannot access field", type, name, e);
} catch (final NoSuchFieldException e) {
throw wrap("Cannot access field", type, name, e);
} catch (final NoClassDefFoundError e) {
} catch (final SecurityException | NoSuchFieldException | NoClassDefFoundError e) {
throw wrap("Cannot access field", type, name, e);
}
}

public static void write(final Field field, final Object instance, final Object value) {
try {
field.set(instance, value);
} catch (final SecurityException e) {
throw wrap("Cannot write field", field.getType(), field.getName(), e);
} catch (final IllegalArgumentException e) {
throw wrap("Cannot write field", field.getType(), field.getName(), e);
} catch (final IllegalAccessException e) {
throw wrap("Cannot write field", field.getType(), field.getName(), e);
} catch (final NoClassDefFoundError e) {
} catch (final SecurityException | IllegalArgumentException | IllegalAccessException | NoClassDefFoundError e) {
throw wrap("Cannot write field", field.getType(), field.getName(), e);
}
}

public static Object read(final Field field, final Object instance) {
try {
return field.get(instance);
} catch (final SecurityException e) {
throw wrap("Cannot read field", field.getType(), field.getName(), e);
} catch (final IllegalArgumentException e) {
throw wrap("Cannot read field", field.getType(), field.getName(), e);
} catch (final IllegalAccessException e) {
throw wrap("Cannot read field", field.getType(), field.getName(), e);
} catch (final NoClassDefFoundError e) {
} catch (final SecurityException | IllegalArgumentException | IllegalAccessException | NoClassDefFoundError e) {
throw wrap("Cannot read field", field.getType(), field.getName(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ public HierarchicalStreamReader createReader(final URL in) {
instream = in.openStream();
return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in.toExternalForm(), instream),
getNameCoder());
} catch (final XMLStreamException e) {
throw new StreamException(e);
} catch (final IOException e) {
} catch (final XMLStreamException | IOException e) {
throw new StreamException(e);
} finally {
if (instream != null) {
Expand All @@ -137,9 +135,7 @@ public HierarchicalStreamReader createReader(final File in) {
instream = new FileInputStream(in);
return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in.toURI().toASCIIString(), instream),
getNameCoder());
} catch (final XMLStreamException e) {
throw new StreamException(e);
} catch (final IOException e) {
} catch (final XMLStreamException | IOException e) {
throw new StreamException(e);
} finally {
if (instream != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009, 2011, 2014, 2018 XStream Committers.
* Copyright (C) 2009, 2011, 2014, 2018, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -54,9 +54,7 @@ public HierarchicalStreamReader createReader(final Reader in) {
final XmlPullParser parser = createParser();
parser.setInput(in);
return new XppDomReader(XppDom.build(parser), getNameCoder());
} catch (final XmlPullParserException e) {
throw new StreamException(e);
} catch (final IOException e) {
} catch (final XmlPullParserException | IOException e) {
throw new StreamException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2016 XStream Committers.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2016, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -109,9 +109,7 @@ public void endNode() {
startElement();
writer.endElement("", "", elementStack.pop());
}
} catch (final SAXException e) {
throw new StreamException(e);
} catch (final IOException e) {
} catch (final SAXException | IOException e) {
throw new StreamException(e);
}
}
Expand Down
10 changes: 2 additions & 8 deletions xstream/src/java/com/thoughtworks/xstream/io/xml/DomDriver.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015, 2020 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -108,13 +108,7 @@ private HierarchicalStreamReader createReader(final InputSource source) {
}
final Document document = documentBuilder.parse(source);
return new DomReader(document, getNameCoder());
} catch (final FactoryConfigurationError e) {
throw new StreamException(e);
} catch (final ParserConfigurationException e) {
throw new StreamException(e);
} catch (final SAXException e) {
throw new StreamException(e);
} catch (final IOException e) {
} catch (final FactoryConfigurationError | ParserConfigurationException | SAXException | IOException e) {
throw new StreamException(e);
}
}
Expand Down

0 comments on commit 470f1cb

Please sign in to comment.