Java 8 migration. Join similar catch blocks (#8767)

Motivation:

We can now use multi-catch blocks.

Modification:

Join similar catch blocks + small cleanup.

Result:

Cleaner code.
This commit is contained in:
Dmitriy Dumanskiy 2019-01-23 14:03:07 +02:00 committed by Norman Maurer
parent 3d6e6136a9
commit 9e9ee2ecd0
2 changed files with 13 additions and 47 deletions

View File

@ -500,9 +500,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
if (charsetAttribute != null) {
try {
localCharset = Charset.forName(charsetAttribute.getValue());
} catch (IOException e) {
throw new ErrorDataDecoderException(e);
} catch (UnsupportedCharsetException e) {
} catch (IOException | UnsupportedCharsetException e) {
throw new ErrorDataDecoderException(e);
}
}
@ -527,11 +525,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
currentAttribute = factory.createAttribute(request,
cleanString(nameAttribute.getValue()));
}
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
} catch (IOException e) {
} catch (NullPointerException | IOException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
if (localCharset != null) {
@ -697,9 +691,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
Attribute attribute;
try {
attribute = getContentDispositionAttribute(values);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(attribute.getName(), attribute);
@ -710,9 +702,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
try {
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(),
cleanString(contents[1]));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
@ -722,9 +712,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
try {
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(),
cleanString(contents[1]));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
@ -748,9 +736,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
Attribute attribute;
try {
attribute = factory.createAttribute(request, charsetHeader, cleanString(values));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(HttpHeaderValues.CHARSET, attribute);
@ -759,9 +745,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
try {
attribute = factory.createAttribute(request,
cleanString(contents[0]), contents[i]);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
}
currentFieldAttributes.put(attribute.getName(), attribute);
@ -819,10 +803,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
name = HttpHeaderValues.FILENAME.toString();
String[] split = value.split("'", 3);
value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0]));
} catch (ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException | UnsupportedCharsetException e) {
throw new ErrorDataDecoderException(e);
} catch (UnsupportedCharsetException e) {
throw new ErrorDataDecoderException(e);
}
} else {
// otherwise we need to clean the value
@ -873,9 +855,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
if (charsetAttribute != null) {
try {
localCharset = Charset.forName(charsetAttribute.getValue());
} catch (IOException e) {
throw new ErrorDataDecoderException(e);
} catch (UnsupportedCharsetException e) {
} catch (IOException | UnsupportedCharsetException e) {
throw new ErrorDataDecoderException(e);
}
}
@ -903,11 +883,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()),
contentType, mechanism.value(), localCharset,
size);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
throw new ErrorDataDecoderException(e);
} catch (IOException e) {
} catch (NullPointerException | IllegalArgumentException | IOException e) {
throw new ErrorDataDecoderException(e);
}
}

View File

@ -35,7 +35,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
@ -180,7 +179,7 @@ public final class NativeLibraryLoader {
int index = libname.lastIndexOf('.');
String prefix = libname.substring(0, index);
String suffix = libname.substring(index, libname.length());
String suffix = libname.substring(index);
tmpFile = File.createTempFile(prefix, suffix, WORKDIR);
in = url.openStream();
@ -307,10 +306,7 @@ public final class NativeLibraryLoader {
loadLibraryByHelper(newHelper, name, absolute);
logger.debug("Successfully loaded the library {}", name);
return;
} catch (UnsatisfiedLinkError e) { // Should by pass the UnsatisfiedLinkError here!
suppressed = e;
logger.debug("Unable to load the library '{}', trying other loading mechanism.", name, e);
} catch (Exception e) {
} catch (UnsatisfiedLinkError | Exception e) { // Should by pass the UnsatisfiedLinkError here!
suppressed = e;
logger.debug("Unable to load the library '{}', trying other loading mechanism.", name, e);
}
@ -388,13 +384,7 @@ public final class NativeLibraryLoader {
}
}
});
} catch (ClassNotFoundException e2) {
ThrowableUtil.addSuppressed(e2, e1);
throw e2;
} catch (RuntimeException e2) {
ThrowableUtil.addSuppressed(e2, e1);
throw e2;
} catch (Error e2) {
} catch (ClassNotFoundException | Error | RuntimeException e2) {
ThrowableUtil.addSuppressed(e2, e1);
throw e2;
}