Skip to content

Commit ec0a9af

Browse files
committed
Add ConfigurationException.ConfigurationException(String, Object...)
1 parent 8292f19 commit ec0a9af

9 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
<author email="dev@commons.apache.org">Apache Commons Community</author>
2424
</properties>
2525
<body>
26-
<release version="2.13.1" date="YYYY-MM-DD" description="Minor release with new features and updated dependencies; requires Java 8 or above.">
26+
<release version="2.14.0" date="YYYY-MM-DD" description="Minor release with new features and updated dependencies; requires Java 8 or above.">
2727
<!-- FIX -->
2828
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Apache RAT plugin console warnings.</action>
2929
<!-- ADD -->
30+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add ConfigurationException.ConfigurationException(String, Object...).</action>
3031
<!-- UPDATE -->
3132
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 92 to 97.</action>
3233
<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/builder/combined/BaseConfigurationBuilderProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected Collection<BuilderParameters> createParameterObjects() throws Exceptio
186186
protected String determineBuilderClass(final ConfigurationDeclaration decl) throws ConfigurationException {
187187
if (decl.isReload()) {
188188
if (getReloadingBuilderClass() == null) {
189-
throw new ConfigurationException("No support for reloading for builder class " + getBuilderClass());
189+
throw new ConfigurationException("No support for reloading for builder class %s", getBuilderClass());
190190
}
191191
return getReloadingBuilderClass();
192192
}

src/main/java/org/apache/commons/configuration2/builder/combined/CombinedConfigurationBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private EventListener<ConfigurationBuilderEvent> createBuilderChangeListener() {
335335
private ConfigurationBuilder<? extends Configuration> createConfigurationBuilder(final ConfigurationDeclaration decl) throws ConfigurationException {
336336
final ConfigurationBuilderProvider provider = providerForTag(decl.getConfiguration().getRootElementName());
337337
if (provider == null) {
338-
throw new ConfigurationException("Unsupported configuration source: " + decl.getConfiguration().getRootElementName());
338+
throw new ConfigurationException("Unsupported configuration source: %s", decl.getConfiguration().getRootElementName());
339339
}
340340

341341
final ConfigurationBuilder<? extends Configuration> builder = provider.getConfigurationBuilder(decl);
@@ -910,7 +910,7 @@ public synchronized ConfigurationBuilder<? extends Configuration> getNamedBuilde
910910
}
911911
final ConfigurationBuilder<? extends Configuration> builder = sourceData.getNamedBuilder(name);
912912
if (builder == null) {
913-
throw new ConfigurationException("Builder cannot be resolved: " + name);
913+
throw new ConfigurationException("Builder cannot be resolved: %s", name);
914914
}
915915
return builder;
916916
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public ConfigurationException(final String message) {
4242
super(message);
4343
}
4444

45+
/**
46+
* Constructs a new {@code ConfigurationException} with specified detail message.
47+
*
48+
* @param format the error message for for {@link String#format(String, Object...)}.
49+
* @param params the error parameters for for {@link String#format(String, Object...)}.
50+
* @since 2.14.0
51+
*/
52+
public ConfigurationException(final String format, Object... params) {
53+
super(String.format(format, params));
54+
}
55+
4556
/**
4657
* Constructs a new {@code ConfigurationException} with specified detail message and nested {@code Throwable}.
4758
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void createPath(final File file) throws ConfigurationException {
110110
if (file != null && !file.exists()) {
111111
final File parent = file.getParentFile();
112112
if (parent != null && !parent.exists() && !parent.mkdirs()) {
113-
throw new ConfigurationException("Cannot create path: " + parent);
113+
throw new ConfigurationException("Cannot create path: %s", parent);
114114
}
115115
}
116116
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public void load(final File file) throws ConfigurationException {
585585
try {
586586
url = FileLocatorUtils.toURL(file);
587587
} catch (final MalformedURLException e1) {
588-
throw new ConfigurationException("Cannot create URL from file " + file);
588+
throw new ConfigurationException("Cannot create URL from file %s", file);
589589
}
590590

591591
load(url);
@@ -964,7 +964,7 @@ private void save(final String fileName, final FileLocator locator) throws Confi
964964
}
965965

966966
if (url == null) {
967-
throw new ConfigurationException("Cannot locate configuration source " + fileName);
967+
throw new ConfigurationException("Cannot locate configuration source %s", fileName);
968968
}
969969
save(url, locator);
970970
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public static URL locate(final FileLocator locator) {
508508
public static URL locateOrThrow(final FileLocator locator) throws ConfigurationException {
509509
final URL url = locate(locator);
510510
if (url == null) {
511-
throw new ConfigurationException("Could not locate: " + locator);
511+
throw new ConfigurationException("Could not locate: %s", locator);
512512
}
513513
return url;
514514
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ public InputStream getInputStream(final URL url) throws ConfigurationException {
107107
}
108108
final FileContent content = file.getContent();
109109
if (content == null) {
110-
final String msg = "Cannot access content of " + file.getName().getFriendlyURI();
111-
throw new ConfigurationException(msg);
110+
throw new ConfigurationException("Cannot access content of %s", file.getName().getFriendlyURI());
112111
}
113112
return content.getInputStream();
114113
} catch (final FileSystemException fse) {
115-
final String msg = "Unable to access " + url.toString();
116-
throw new ConfigurationException(msg, fse);
114+
throw new ConfigurationException("Unable to access " + url.toString(), fse);
117115
}
118116
}
119117

@@ -172,7 +170,7 @@ public OutputStream getOutputStream(final URL url) throws ConfigurationException
172170
final FileContent content = file.getContent();
173171

174172
if (content == null) {
175-
throw new ConfigurationException("Cannot access content of " + url);
173+
throw new ConfigurationException("Cannot access content of %s", url);
176174
}
177175
return content.getOutputStream();
178176
} catch (final FileSystemException fse) {

src/main/java/org/apache/commons/configuration2/resolver/CatalogResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public InputSource resolveEntity(final String publicId, final String systemId) t
420420
try {
421421
final URL url = locate(fs, null, resolved);
422422
if (url == null) {
423-
throw new ConfigurationException("Could not locate " + resolved);
423+
throw new ConfigurationException("Could not locate %s", resolved);
424424
}
425425
final InputStream inputStream = fs.getInputStream(url);
426426
final InputSource inputSource = new InputSource(resolved);

0 commit comments

Comments
 (0)