Reduce magic number usage.

This commit is contained in:
Gary Gregory 2020-01-24 09:05:31 -05:00
parent a606a0328b
commit bb5244814c
1 changed files with 6 additions and 4 deletions

View File

@ -39,6 +39,8 @@
*/ */
public class ExceptionUtils { public class ExceptionUtils {
private static final int NOT_FOUND = -1;
/** /**
* <p>The names of methods commonly used to access a wrapped exception.</p> * <p>The names of methods commonly used to access a wrapped exception.</p>
*/ */
@ -299,7 +301,7 @@ static List<String> getStackFrameList(final Throwable t) {
final String token = frames.nextToken(); final String token = frames.nextToken();
// Determine if the line starts with <whitespace>at // Determine if the line starts with <whitespace>at
final int at = token.indexOf("at"); final int at = token.indexOf("at");
if (at != -1 && token.substring(0, at).trim().isEmpty()) { if (at != NOT_FOUND && token.substring(0, at).trim().isEmpty()) {
traceStarted = true; traceStarted = true;
list.add(token); list.add(token);
} else if (traceStarted) { } else if (traceStarted) {
@ -475,14 +477,14 @@ public static boolean hasCause(Throwable chain,
*/ */
private static int indexOf(final Throwable throwable, final Class<?> type, int fromIndex, final boolean subclass) { private static int indexOf(final Throwable throwable, final Class<?> type, int fromIndex, final boolean subclass) {
if (throwable == null || type == null) { if (throwable == null || type == null) {
return -1; return NOT_FOUND;
} }
if (fromIndex < 0) { if (fromIndex < 0) {
fromIndex = 0; fromIndex = 0;
} }
final Throwable[] throwables = getThrowables(throwable); final Throwable[] throwables = getThrowables(throwable);
if (fromIndex >= throwables.length) { if (fromIndex >= throwables.length) {
return -1; return NOT_FOUND;
} }
if (subclass) { if (subclass) {
for (int i = fromIndex; i < throwables.length; i++) { for (int i = fromIndex; i < throwables.length; i++) {
@ -497,7 +499,7 @@ private static int indexOf(final Throwable throwable, final Class<?> type, int f
} }
} }
} }
return -1; return NOT_FOUND;
} }
/** /**