Skip to content

Commit 9e6852e

Browse files
committed
Rename Exceptions utility class to Threads
And remove the public iae methods.
1 parent 00afd00 commit 9e6852e

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

scijava-common3/src/main/java/org/scijava/common3/Classes.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
package org.scijava.common3;
3131

32-
import static org.scijava.common3.Exceptions.iae;
33-
3432
import java.lang.reflect.Array;
3533
import java.lang.reflect.Field;
3634
import java.lang.reflect.Method;
@@ -183,7 +181,7 @@ public static Class<?> load(final String name, final ClassLoader classLoader,
183181
// Not NoClassDefFoundError.
184182
// Not UnsupportedClassVersionError!
185183
if (quietly) return null;
186-
throw iae(t, "Cannot load class: " + className);
184+
throw iae(t, "Cannot load class: %s", className);
187185
}
188186
}
189187

@@ -250,15 +248,15 @@ public static URL location(final Class<?> c, final boolean quietly) {
250248
if (classResource == null) {
251249
// cannot find class resource
252250
if (quietly) return null;
253-
throw iae(cause, "No class resource for class: " + c.getName(), why);
251+
throw iae(cause, "No class resource for class: %s (%s)", c.getName(), why);
254252
}
255253

256254
final String url = classResource.toString();
257255
final String suffix = c.getCanonicalName().replace('.', '/') + ".class";
258256
if (!url.endsWith(suffix)) {
259257
// weird URL
260258
if (quietly) return null;
261-
throw iae(cause, "Unsupported URL format: " + url, why);
259+
throw iae(cause, "Unsupported URL format: %s (%s)", url, why);
262260
}
263261

264262
// strip the class's path from the URL string
@@ -274,7 +272,7 @@ public static URL location(final Class<?> c, final boolean quietly) {
274272
}
275273
catch (final MalformedURLException e) {
276274
if (quietly) return null;
277-
throw iae(e, "Malformed URL", why);
275+
throw iae(e, "Malformed URL: %s (%s)", path, why);
278276
}
279277
}
280278

@@ -436,7 +434,7 @@ public static <T> T nullValue(final Class<T> type) {
436434
* field with the given name
437435
*/
438436
public static Field field(final Class<?> c, final String name) {
439-
if (c == null) throw iae("No such field: " + name);
437+
if (c == null) throw iae(null, "No such field: %s", name);
440438
try {
441439
return c.getDeclaredField(name);
442440
}
@@ -473,7 +471,7 @@ public static Field field(final Class<?> c, final String name) {
473471
public static Method method(final Class<?> c, final String name,
474472
final Class<?>... parameterTypes)
475473
{
476-
if (c == null) throw iae("No such field: " + name);
474+
if (c == null) throw iae(null, "No such field: %s", name);
477475
try {
478476
return c.getDeclaredMethod(name, parameterTypes);
479477
}
@@ -514,7 +512,7 @@ public static Class<?> array(final Class<?> componentType) {
514512
* @param dim The dimensionality of the array
515513
*/
516514
public static Class<?> array(final Class<?> componentType, final int dim) {
517-
if (dim < 0) throw iae("Negative dimension");
515+
if (dim < 0) throw iae(null, "Negative dimension");
518516
if (dim == 0) return componentType;
519517
return array(array(componentType), dim - 1);
520518
}
@@ -551,4 +549,17 @@ private static Class<?> arrayOrNull(final Class<?> componentType) {
551549
return null;
552550
}
553551
}
552+
553+
/**
554+
* Creates a new {@link IllegalArgumentException} with the given cause and
555+
* formatted message string.
556+
*/
557+
private static IllegalArgumentException iae(final Throwable cause,
558+
final String formattedMessage, final String... values)
559+
{
560+
final String s = String.format(formattedMessage, values);
561+
final IllegalArgumentException exc = new IllegalArgumentException(s);
562+
if (cause != null) exc.initCause(cause);
563+
return exc;
564+
}
554565
}

scijava-common3/src/main/java/org/scijava/common3/Exceptions.java renamed to scijava-common3/src/main/java/org/scijava/common3/Threads.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,19 @@
3737
import java.util.Map;
3838

3939
/**
40-
* Utility class for working with {@link Exception}s.
40+
* Utility class for working with {@link Thread}s.
4141
*
4242
* @author Curtis Rueden
4343
* @author Gabriel Selzer
4444
*/
45-
public final class Exceptions {
45+
public final class Threads {
4646

4747
private static final String NL = System.getProperty("line.separator");
4848

49-
private Exceptions() {
49+
private Threads() {
5050
// prevent instantiation of utility class
5151
}
5252

53-
/**
54-
* Creates a new {@link IllegalArgumentException} with the given message
55-
* strings joined by commas.
56-
*/
57-
public static IllegalArgumentException iae(final String... notes) {
58-
return iae(null, notes);
59-
}
60-
61-
/**
62-
* Creates a new {@link IllegalArgumentException} with the given cause and
63-
* message strings joined by commas.
64-
*/
65-
public static IllegalArgumentException iae(final Throwable cause,
66-
final String... notes)
67-
{
68-
final String s = String.join(", ", notes);
69-
final IllegalArgumentException exc = new IllegalArgumentException(s);
70-
if (cause != null) exc.initCause(cause);
71-
return exc;
72-
}
73-
7453
/** Extracts the given exception's corresponding stack trace to a string. */
7554
public static String stackTrace(final Throwable t) {
7655
try {

scijava-types/src/main/java/org/scijava/types/Types.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
//
4343
// See NOTICE.txt for further details on third-party licenses.
4444

45-
import static org.scijava.common3.Exceptions.iae;
46-
4745
import java.io.Serializable;
4846
import java.lang.reflect.Field;
4947
import java.lang.reflect.GenericArrayType;
@@ -966,7 +964,9 @@ public static Type mapVarToTypes(Type typeToMap,
966964
* has no such constant.
967965
*/
968966
public static <T> T enumValue(final String name, final Class<T> dest) {
969-
if (!dest.isEnum()) throw iae("Not an enum type: " + name(dest));
967+
if (!dest.isEnum()) {
968+
throw new IllegalArgumentException("Not an enum type: " + name(dest));
969+
}
970970
@SuppressWarnings({ "rawtypes", "unchecked" })
971971
final Enum result = Enum.valueOf((Class) dest, name);
972972
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)