in nifi-extension-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/util/Throwables.java [53:151]
public static String getMessage(Throwable e, Object priority, int maxlen) {
if (e == null) {
return null;
}
e = getRootException(e);
StackTraceElement[] trace = e.getStackTrace();
int traceIndex = -1;
if (priority != null) {
if (priority instanceof String) {
for (int i = 0; i < trace.length; i++) {
if (trace[i].getClassName().startsWith((String) priority)) {
traceIndex = i;
break;
}
}
} else {
if (!(priority instanceof Class)) {
priority = priority.getClass();
}
String cl = ((Class) priority).getName();
for (int i = 0; i < trace.length; i++) {
if (trace[i].getClassName().startsWith(cl)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
cl = ((Class) priority).getPackage().getName();
for (int i = 0; i < trace.length; i++) {
if (trace[i].getClassName().startsWith(cl)) {
traceIndex = i;
break;
}
}
}
}
}
if (traceIndex == -1) {
for (int i = 0; i < trace.length; i++) {
String cl = trace[i].getClassName();
if (cl.startsWith("java.") || cl.startsWith("javax.") || cl.startsWith("org.omg.") || cl.startsWith("org.w3c.") || cl.startsWith("org.xml.") || cl.startsWith("groovy.lang.") || cl
.startsWith("groovy.util.") || cl.startsWith("org.codehaus.") || cl.startsWith("com.springsource.") || cl.startsWith("org.springframework.") || cl.startsWith("org.apache.")
|| cl.startsWith("sun.") || cl.startsWith("com.sun.") || cl.startsWith("org.junit.") || cl.startsWith("junit.framework.")
) {
//skip standard classes
} else {
traceIndex = i;
break;
}
}
}
if (traceIndex == -1) {
traceIndex = 0;
}
//build message text
String msg = e.getMessage();
if (msg == null) {
msg = "";
}
msg = msg.trim();
//append dot at the end if no others
if (msg.length() > 0 && ".!:,;?".indexOf(msg.substring(msg.length() - 1)) == -1) {
msg += ".";
}
//exception class name without package
String msgSuffix = " " + e.getClass().getName().replaceAll("^.*\\.(\\w+)$", "$1") + " at ";
//append callers line
if (traceIndex < 0 || traceIndex >= trace.length) {
System.err.println("Error formatting exception: " + e);
e.printStackTrace(System.err);
msgSuffix = e.getClass().getName();
} else {
msgSuffix += trace[traceIndex].toString();
}
if (maxlen > 0 && msgSuffix.length() + msg.length() > maxlen) {
if (maxlen > msgSuffix.length() + 2) {
int newlen = maxlen - msgSuffix.length() - 2;
if (newlen < msg.length()) {
msg = msg.substring(0, newlen);
}
msg = msg + ".." + msgSuffix;
} else if (msg.length() > maxlen) {
msg = msg.substring(0, maxlen);
}
} else {
msg = msg + msgSuffix;
}
return msg;
}