Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide BlockHound's own frame from the Error #62

Merged
merged 4 commits into from
Oct 30, 2019

Conversation

bsideup
Copy link
Contributor

@bsideup bsideup commented Oct 23, 2019

Since we instrument the blocking methods, we add more frames to the stack of the thrown exception. We could artificially remove them from the created java.lang.Error instance to not confuse the users with something they do not expect.

Before:

java.lang.Error: Blocking call! java.lang.Thread.sleep
	at reactor.blockhound.BlockHound$Builder.lambda$new$0(BlockHound.java:196)
	at reactor.blockhound.BlockHound$Builder.lambda$install$6(BlockHound.java:338)
	at reactor.blockhound.BlockHoundRuntime.checkBlocking(BlockHoundRuntime.java:46)
	at java.base/java.lang.Thread.sleep(Thread.java)
	at com.example.StrackTraceTest.lambda$shouldHideInternalFrames$0(StrackTraceTest.java:41)

After:

java.lang.Error: Blocking call! java.lang.Thread.sleep
	at java.base/java.lang.Thread.sleep(Thread.java)
	at com.example.StrackTraceTest.lambda$shouldHideInternalFrames$0(StrackTraceTest.java:41)

@bsideup bsideup added type/enhancement A general enhancement area/java-agent labels Oct 23, 2019
@bsideup bsideup added this to the next milestone Oct 23, 2019

if ("checkBlocking".equals(stackTraceElement.getMethodName())) {
if (i + 1 < length) {
System.arraycopy(stackTrace, i + 1, stackTrace, 0, length - i - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't change the size of the stackTrace array, leading to duplicated stacktrace elements 💥

verified with strings:

String[] array = new String[] { "A", "B", "C", "D" };
System.arraycopy(array, 2, array, 0, 2);

System.out.println(array.length);
for (String s : array) {
	System.out.println(s);
}

prints 4 C D C D

you can probably use Arrays.copyOfRange, or emulate its core behavior which might perform slightly better (no .class manipulation and no Array.newInstance):

System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Great catch 🤦‍♂

Fixing... 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks a lot for spotting it! 👍

…mes_from_error

# Conflicts:
#	agent/src/main/java/reactor/blockhound/BlockHound.java
@bsideup bsideup merged commit 7092674 into master Oct 30, 2019
@bsideup bsideup deleted the hide_blockhound_frames_from_error branch October 30, 2019 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants