reactor / BlockHound

Java agent to detect blocking calls from non-blocking threads.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to ignore blocking calls in a static initializer

UgiR opened this issue · comments

Not sure if it is possible, but it would be useful to have the option to ignore blocking calls occurring in the initialization of static fields.

Motivation

In this specific example, Build will use an InputStream, but the resulting blocking call to readBytes is not detrimental to the event loop threads in the long run, since it is only called once when the string is initialized.

static {
		PREFIX = String.format(Locale.ROOT,
				"%s%s",
				Version.CURRENT.toString(),
				Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : "");
	}

Thanks, I will take a look.

Meanwhile, you can extract a method, whitelist it and call it from your static block, as a workaround.

Hi @UgiR,
Thanks for reporting!

I just fixed an issue, it seems that ByteBuddy's getName() wasn't the right method to use since it returns class' name for the static initializers.

As a workaround before the next release, you can use something like:

b.allowBlockingCallsInside(ClassWithStaticInit.class.getName(), ClassWithStaticInit.class.getName());