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:
parent
3d6e6136a9
commit
9e9ee2ecd0
@ -500,9 +500,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
if (charsetAttribute != null) {
|
if (charsetAttribute != null) {
|
||||||
try {
|
try {
|
||||||
localCharset = Charset.forName(charsetAttribute.getValue());
|
localCharset = Charset.forName(charsetAttribute.getValue());
|
||||||
} catch (IOException e) {
|
} catch (IOException | UnsupportedCharsetException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (UnsupportedCharsetException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,11 +525,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
currentAttribute = factory.createAttribute(request,
|
currentAttribute = factory.createAttribute(request,
|
||||||
cleanString(nameAttribute.getValue()));
|
cleanString(nameAttribute.getValue()));
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IOException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
if (localCharset != null) {
|
if (localCharset != null) {
|
||||||
@ -697,9 +691,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
Attribute attribute;
|
Attribute attribute;
|
||||||
try {
|
try {
|
||||||
attribute = getContentDispositionAttribute(values);
|
attribute = getContentDispositionAttribute(values);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
currentFieldAttributes.put(attribute.getName(), attribute);
|
currentFieldAttributes.put(attribute.getName(), attribute);
|
||||||
@ -710,9 +702,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
try {
|
try {
|
||||||
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(),
|
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(),
|
||||||
cleanString(contents[1]));
|
cleanString(contents[1]));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,9 +712,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
try {
|
try {
|
||||||
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(),
|
attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(),
|
||||||
cleanString(contents[1]));
|
cleanString(contents[1]));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,9 +736,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
Attribute attribute;
|
Attribute attribute;
|
||||||
try {
|
try {
|
||||||
attribute = factory.createAttribute(request, charsetHeader, cleanString(values));
|
attribute = factory.createAttribute(request, charsetHeader, cleanString(values));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
currentFieldAttributes.put(HttpHeaderValues.CHARSET, attribute);
|
currentFieldAttributes.put(HttpHeaderValues.CHARSET, attribute);
|
||||||
@ -759,9 +745,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
try {
|
try {
|
||||||
attribute = factory.createAttribute(request,
|
attribute = factory.createAttribute(request,
|
||||||
cleanString(contents[0]), contents[i]);
|
cleanString(contents[0]), contents[i]);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
currentFieldAttributes.put(attribute.getName(), attribute);
|
currentFieldAttributes.put(attribute.getName(), attribute);
|
||||||
@ -819,10 +803,8 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
name = HttpHeaderValues.FILENAME.toString();
|
name = HttpHeaderValues.FILENAME.toString();
|
||||||
String[] split = value.split("'", 3);
|
String[] split = value.split("'", 3);
|
||||||
value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0]));
|
value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0]));
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException | UnsupportedCharsetException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
} catch (UnsupportedCharsetException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// otherwise we need to clean the value
|
// otherwise we need to clean the value
|
||||||
@ -873,9 +855,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
if (charsetAttribute != null) {
|
if (charsetAttribute != null) {
|
||||||
try {
|
try {
|
||||||
localCharset = Charset.forName(charsetAttribute.getValue());
|
localCharset = Charset.forName(charsetAttribute.getValue());
|
||||||
} catch (IOException e) {
|
} catch (IOException | UnsupportedCharsetException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (UnsupportedCharsetException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -903,11 +883,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()),
|
cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()),
|
||||||
contentType, mechanism.value(), localCharset,
|
contentType, mechanism.value(), localCharset,
|
||||||
size);
|
size);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException | IllegalArgumentException | IOException e) {
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ErrorDataDecoderException(e);
|
throw new ErrorDataDecoderException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -180,7 +179,7 @@ public final class NativeLibraryLoader {
|
|||||||
|
|
||||||
int index = libname.lastIndexOf('.');
|
int index = libname.lastIndexOf('.');
|
||||||
String prefix = libname.substring(0, index);
|
String prefix = libname.substring(0, index);
|
||||||
String suffix = libname.substring(index, libname.length());
|
String suffix = libname.substring(index);
|
||||||
|
|
||||||
tmpFile = File.createTempFile(prefix, suffix, WORKDIR);
|
tmpFile = File.createTempFile(prefix, suffix, WORKDIR);
|
||||||
in = url.openStream();
|
in = url.openStream();
|
||||||
@ -307,10 +306,7 @@ public final class NativeLibraryLoader {
|
|||||||
loadLibraryByHelper(newHelper, name, absolute);
|
loadLibraryByHelper(newHelper, name, absolute);
|
||||||
logger.debug("Successfully loaded the library {}", name);
|
logger.debug("Successfully loaded the library {}", name);
|
||||||
return;
|
return;
|
||||||
} catch (UnsatisfiedLinkError e) { // Should by pass the UnsatisfiedLinkError here!
|
} 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);
|
|
||||||
} catch (Exception e) {
|
|
||||||
suppressed = e;
|
suppressed = e;
|
||||||
logger.debug("Unable to load the library '{}', trying other loading mechanism.", name, 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) {
|
} catch (ClassNotFoundException | Error | RuntimeException e2) {
|
||||||
ThrowableUtil.addSuppressed(e2, e1);
|
|
||||||
throw e2;
|
|
||||||
} catch (RuntimeException e2) {
|
|
||||||
ThrowableUtil.addSuppressed(e2, e1);
|
|
||||||
throw e2;
|
|
||||||
} catch (Error e2) {
|
|
||||||
ThrowableUtil.addSuppressed(e2, e1);
|
ThrowableUtil.addSuppressed(e2, e1);
|
||||||
throw e2;
|
throw e2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user