diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/ExceptionUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/ExceptionUtils.java index e5651fb78a40fc229899bb84aa44554806dbae18..a8c1cdc5e7f037102dc943b4f7ca141116ff248f 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/ExceptionUtils.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/ExceptionUtils.java @@ -27,9 +27,9 @@ import ch.systemsx.cisd.common.exceptions.IndependentException; public final class ExceptionUtils { /** - * The package names considered as client-safe. + * Accepted packages for dependencies. */ - private static String[] CLIENT_SAFE_PACKAGE_NAMES = + private static String[] ACCEPTED_DEPENDENCIES_PACKAGE_NAMES = { "java.lang", "ch.systemsx.cisd" }; ExceptionUtils() @@ -38,13 +38,13 @@ public final class ExceptionUtils } /** - * Creates a new <code>ClientSafeException</code> from given <var>exception</var> only if it is needed ({@link #isClientSafe(Exception)} + * Creates a new {@link IndependentException} from given <var>exception</var> only if it is needed ({@link #isIndependent(Exception)} * returns <code>false</code>). Otherwise returns given <var>exception</var>. */ - private final static Exception createClientSafeException(final Exception exception) + private final static Exception createIndependentException(final Exception exception) { final Exception rootException = CheckedExceptionTunnel.unwrapIfNecessary(exception); - if (isClientSafe(rootException) == false) + if (isIndependent(rootException) == false) { return new IndependentException(rootException); } else @@ -62,7 +62,7 @@ public final class ExceptionUtils (Exception) org.apache.commons.lang.exception.ExceptionUtils.getCause(fromException); if (fromCauseException != null && fromCauseException != fromException) { - final Exception toCauseException = createClientSafeException(fromCauseException); + final Exception toCauseException = createIndependentException(fromCauseException); if (toException.getCause() != toCauseException) { if (ClassUtils.setFieldValue(toException, "cause", toCauseException) == false) @@ -77,11 +77,11 @@ public final class ExceptionUtils /** * Whether given <var>exception</var> is client-safe or not. */ - final static boolean isClientSafe(final Exception exception) + final static boolean isIndependent(final Exception exception) { assert exception != null : "Unspecified exception."; final String className = exception.getClass().getName(); - for (final String packageName : CLIENT_SAFE_PACKAGE_NAMES) + for (final String packageName : ACCEPTED_DEPENDENCIES_PACKAGE_NAMES) { if (className.startsWith(packageName)) { @@ -92,12 +92,13 @@ public final class ExceptionUtils } /** - * Analyzes given <var>exception</var> and makes it client-safe. + * Analyzes given <var>exception</var> and makes it independent to packages outside the ones specified in + * {@link #ACCEPTED_DEPENDENCIES_PACKAGE_NAMES}. */ - public final static Exception createClientSafeExceptionIfNeeded(final Exception exception) + public final static Exception createIndependentExceptionIfNeeded(final Exception exception) { assert exception != null : "Unspecified SQL Exception."; - final Exception clientSafeException = createClientSafeException(exception); + final Exception clientSafeException = createIndependentException(exception); copyCauseException(exception, clientSafeException); return clientSafeException; } diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ExceptionUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ExceptionUtilsTest.java index d976a7c1cb6518696a4e9ea6a93f8b6d7bc0b9b9..6454de84fb16cadb6a1d47ad4f0d6e692d749462 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ExceptionUtilsTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ExceptionUtilsTest.java @@ -65,7 +65,7 @@ public final class ExceptionUtilsTest { try { - ExceptionUtils.createClientSafeExceptionIfNeeded(null); + ExceptionUtils.createIndependentExceptionIfNeeded(null); fail("Null exception not allowed."); } catch (final AssertionError ex) { @@ -78,7 +78,7 @@ public final class ExceptionUtilsTest { final String message = "Oooops!"; final UserFailureException exception = new UserFailureException(message); - final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(exception); + final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(exception); checkReturnedClientSafeException(message, exception, clientSafeException, true); } @@ -87,7 +87,7 @@ public final class ExceptionUtilsTest { final String message = "Oooops!"; final Exception exception = new SAXException(message); - final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(exception); + final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(exception); checkReturnedClientSafeException(message, exception, clientSafeException, false); } @@ -102,7 +102,7 @@ public final class ExceptionUtilsTest final UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException(unsupportedOperationText, runtimeException); final Exception clientSafeException = - ExceptionUtils.createClientSafeExceptionIfNeeded(unsupportedOperationException); + ExceptionUtils.createIndependentExceptionIfNeeded(unsupportedOperationException); checkReturnedClientSafeException(unsupportedOperationText, unsupportedOperationException, clientSafeException, true); checkReturnedClientSafeException(runtimeText, runtimeException, (Exception) clientSafeException.getCause(), @@ -120,7 +120,7 @@ public final class ExceptionUtilsTest final RuntimeException runtimeException = new RuntimeException(runtimeText, saxException); final String digestExceptionText = "Wishiiiii!"; final DigestException digestException = new DigestException(digestExceptionText, runtimeException); - final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(digestException); + final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(digestException); checkReturnedClientSafeException(digestExceptionText, digestException, clientSafeException, false); checkReturnedClientSafeException(runtimeText, runtimeException, (Exception) clientSafeException.getCause(), true); @@ -134,7 +134,7 @@ public final class ExceptionUtilsTest final String text = "Oooops!"; final IOException ioException = new IOException(text); final RuntimeException checkedExceptionTunnel = CheckedExceptionTunnel.wrapIfNecessary(ioException); - final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(checkedExceptionTunnel); + final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(checkedExceptionTunnel); assertNotSame(clientSafeException, checkedExceptionTunnel); assertNotSame(clientSafeException, ioException); assertTrue(clientSafeException instanceof IndependentException);