-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StackWalker.Option not found on Mockito 5.1.0 (#2891)
Fixes #2890 Signed-off-by: Andriy Redko <drreta@gmail.com>
- Loading branch information
Showing
2 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/org/mockito/internal/debugging/Java8LocationImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2007 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.debugging; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.mockito.internal.exceptions.stacktrace.StackTraceFilter; | ||
import org.mockito.invocation.Location; | ||
|
||
class Java8LocationImpl implements Location, Serializable { | ||
|
||
private static final long serialVersionUID = -9054861157390980624L; | ||
// Limit the amount of objects being created, as this class is heavily instantiated: | ||
private static final StackTraceFilter stackTraceFilter = new StackTraceFilter(); | ||
|
||
private String stackTraceLine; | ||
private String sourceFile; | ||
|
||
public Java8LocationImpl(Throwable stackTraceHolder, boolean isInline) { | ||
this(stackTraceFilter, stackTraceHolder, isInline); | ||
} | ||
|
||
private Java8LocationImpl( | ||
StackTraceFilter stackTraceFilter, Throwable stackTraceHolder, boolean isInline) { | ||
computeStackTraceInformation(stackTraceFilter, stackTraceHolder, isInline); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return stackTraceLine; | ||
} | ||
|
||
/** | ||
* Eagerly compute the stacktrace line from the stackTraceHolder. Storing the Throwable is | ||
* memory-intensive for tests that have large stacktraces and have a lot of invocations on | ||
* mocks. | ||
*/ | ||
private void computeStackTraceInformation( | ||
StackTraceFilter stackTraceFilter, Throwable stackTraceHolder, boolean isInline) { | ||
StackTraceElement filtered = stackTraceFilter.filterFirst(stackTraceHolder, isInline); | ||
|
||
// there are corner cases where exception can have a null or empty stack trace | ||
// for example, a custom exception can override getStackTrace() method | ||
if (filtered == null) { | ||
this.stackTraceLine = "-> at <<unknown line>>"; | ||
this.sourceFile = "<unknown source file>"; | ||
} else { | ||
this.stackTraceLine = "-> at " + filtered; | ||
this.sourceFile = filtered.getFileName(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getSourceFile() { | ||
return sourceFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters