Skip to content

Commit cd6464b

Browse files
committed
Add and use
ConfigurationRuntimeException.ConfigurationRuntimeException(Throwable, String, Object...)
1 parent 730a941 commit cd6464b

9 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ConfigurationException.ConfigurationException(Throwable, String, Object...).</action>
3434
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ConversionException.ConversionException(String, Object...).</action>
3535
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ConversionException.ConversionException(Throwable, String, Object...).</action>
36+
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ConfigurationRuntimeException.ConfigurationRuntimeException(Throwable, String, Object...).</action>
3637
<!-- UPDATE -->
3738
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 92 to 97.</action>
3839
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-text from 1.14.0 to 1.15.0.</action>

src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ public static Class<?> loadClass(final String clsName) throws ClassNotFoundExcep
446446
public static Class<?> loadClassNoEx(final String clsName) {
447447
try {
448448
return loadClass(clsName);
449-
} catch (final ClassNotFoundException cnfex) {
450-
throw new ConfigurationRuntimeException("Cannot load class " + clsName, cnfex);
449+
} catch (final ClassNotFoundException e) {
450+
throw new ConfigurationRuntimeException(e, "Cannot load class %s", clsName);
451451
}
452452
}
453453

src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ protected static String unescapeJava(final String str, final boolean jupCompatib
11811181
unicode.setLength(0);
11821182
inUnicode = false;
11831183
hadSlash = false;
1184-
} catch (final NumberFormatException nfe) {
1185-
throw new ConfigurationRuntimeException("Unable to parse unicode value: " + unicode, nfe);
1184+
} catch (final NumberFormatException e) {
1185+
throw new ConfigurationRuntimeException(e, "Unable to parse unicode value: %s", unicode);
11861186
}
11871187
}
11881188
continue;

src/main/java/org/apache/commons/configuration2/ex/ConfigurationRuntimeException.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ public ConfigurationRuntimeException(final String message) {
4545
}
4646

4747
/**
48-
* Constructs a new {@code ConfigurationRuntimeException} with specified detail message using
49-
* {@link String#format(String,Object...)}.
48+
* Constructs a new {@code ConfigurationRuntimeException} with specified detail message using {@link String#format(String,Object...)}.
5049
*
5150
* @param message the error message
52-
* @param args arguments to the error message
51+
* @param args arguments to the error message
5352
* @see String#format(String,Object...)
5453
*/
5554
public ConfigurationRuntimeException(final String message, final Object... args) {
@@ -60,7 +59,7 @@ public ConfigurationRuntimeException(final String message, final Object... args)
6059
* Constructs a new {@code ConfigurationRuntimeException} with specified detail message and nested {@code Throwable}.
6160
*
6261
* @param message the error message
63-
* @param cause the exception or error that caused this exception to be thrown
62+
* @param cause the exception or error that caused this exception to be thrown
6463
*/
6564
public ConfigurationRuntimeException(final String message, final Throwable cause) {
6665
super(message, cause);
@@ -74,4 +73,17 @@ public ConfigurationRuntimeException(final String message, final Throwable cause
7473
public ConfigurationRuntimeException(final Throwable cause) {
7574
super(cause);
7675
}
76+
77+
/**
78+
* Constructs a new {@code ConfigurationRuntimeException} with specified detail message.
79+
*
80+
* @param format the error message for for {@link String#format(String, Object...)}.
81+
* @param params the error parameters for for {@link String#format(String, Object...)}.
82+
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value is permitted, and indicates that
83+
* the cause is nonexistent or unknown.)
84+
* @since 2.14.0
85+
*/
86+
public ConfigurationRuntimeException(final Throwable cause, final String format, final Object... params) {
87+
super(String.format(format, params), cause);
88+
}
7789
}

src/main/java/org/apache/commons/configuration2/ex/ConversionException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public ConversionException(final Throwable cause) {
8484
* @since 2.14.0
8585
*/
8686
public ConversionException(final Throwable cause, final String format, final Object... params) {
87-
super(String.format(format, params), cause);
87+
super(cause, format, params);
8888
}
8989
}

src/main/java/org/apache/commons/configuration2/interpol/ExprLookup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void setValue(final Object value) throws ConfigurationRuntimeException {
140140
this.value = clazz;
141141
}
142142
} catch (final Exception e) {
143-
throw new ConfigurationRuntimeException("Unable to create " + value, e);
143+
throw new ConfigurationRuntimeException(e, "Unable to create %s", value);
144144
}
145145

146146
}

src/main/java/org/apache/commons/configuration2/io/VFSFileSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public URL getURL(final String basePath, final String file) throws MalformedURLE
222222

223223
final URLStreamHandler handler = new VFSURLStreamHandler();
224224
return new URL(null, path.getURI(), handler);
225-
} catch (final FileSystemException fse) {
226-
throw new ConfigurationRuntimeException("Could not parse basePath: " + basePath + " and fileName: " + file, fse);
225+
} catch (final FileSystemException e) {
226+
throw new ConfigurationRuntimeException(e, "Could not parse basePath: %s and fileName: %s", basePath, file);
227227
}
228228
}
229229

src/main/java/org/apache/commons/configuration2/reloading/VFSFileHandlerReloadingDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ protected FileObject getFileObject() {
9393
throw new ConfigurationRuntimeException("Unable to determine file to monitor");
9494
}
9595
return fsManager.resolveFile(uri);
96-
} catch (final FileSystemException fse) {
96+
} catch (final FileSystemException e) {
9797
final String msg = "Unable to monitor " + getFileHandler().getURL().toString();
9898
log.error(msg);
99-
throw new ConfigurationRuntimeException(msg, fse);
99+
throw new ConfigurationRuntimeException(msg, e);
100100
}
101101
}
102102

src/test/java/org/apache/commons/configuration2/DatabaseConfigurationTestHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public DataSource getDataSource() {
106106
if (dataSource == null) {
107107
try {
108108
dataSource = setUpDataSource();
109-
} catch (final Exception ex) {
110-
throw new ConfigurationRuntimeException("Could not create data source", ex);
109+
} catch (final Exception e) {
110+
throw new ConfigurationRuntimeException("Could not create data source", e);
111111
}
112112
}
113113
return dataSource;

0 commit comments

Comments
 (0)