Home / Class/ StackTrace Class — spring-boot Architecture

StackTrace Class — spring-boot Architecture

Architecture documentation for the StackTrace class in StandardStackTracePrinter.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/main/java/org/springframework/boot/logging/StandardStackTracePrinter.java lines 399–484

	private static final class StackTrace {

		private final Throwable throwable;

		private final StackTraceElement @Nullable [] frames;

		private StackTrace @Nullable [] suppressed;

		private @Nullable StackTrace cause;

		private @Nullable Integer hash;

		private @Nullable String hashPrefix;

		private StackTrace(Throwable throwable) {
			this.throwable = throwable;
			this.frames = (throwable != null) ? throwable.getStackTrace() : null;
		}

		Throwable throwable() {
			return this.throwable;
		}

		StackTraceElement @Nullable [] frames() {
			return this.frames;
		}

		int commonFramesCount(@Nullable StackTrace other) {
			if (other == null || this.frames == null || other.frames == null) {
				return 0;
			}
			int index = this.frames.length - 1;
			int otherIndex = other.frames.length - 1;
			while (index >= 0 && otherIndex >= 0 && this.frames[index].equals(other.frames[otherIndex])) {
				index--;
				otherIndex--;
			}
			return this.frames.length - 1 - index;
		}

		StackTrace @Nullable [] suppressed() {
			if (this.suppressed == null && this.throwable != null) {
				this.suppressed = Arrays.stream(this.throwable.getSuppressed())
					.map(StackTrace::new)
					.toArray(StackTrace[]::new);
			}
			return this.suppressed;
		}

		@Nullable StackTrace cause() {
			if (this.cause == null && this.throwable != null) {
				Throwable cause = this.throwable.getCause();
				this.cause = (cause != null) ? new StackTrace(cause) : null;
			}
			return this.cause;
		}

		String hashPrefix(@Nullable ToIntFunction<StackTraceElement> frameHasher) {
			if (frameHasher == null || throwable() == null) {
				return "";
			}
			this.hashPrefix = (this.hashPrefix != null) ? this.hashPrefix
					: String.format("<#%08x> ", hash(new HashSet<>(), frameHasher));
			return this.hashPrefix;
		}

		private int hash(HashSet<Throwable> seen, ToIntFunction<StackTraceElement> frameHasher) {
			if (this.hash != null) {
				return this.hash;
			}
			int hash = 0;
			StackTrace cause = cause();
			if (cause != null && seen.add(cause.throwable())) {
				hash = cause.hash(seen, frameHasher);
			}
			hash = 31 * hash + throwable().getClass().getName().hashCode();
			if (frames() != null) {
				for (StackTraceElement frame : frames()) {
					hash = 31 * hash + frameHasher.applyAsInt(frame);
				}
			}
			this.hash = hash;
			return hash;
		}

	}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free