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

Ability to ignore blocking calls in a static initializer #63

Closed
UgiR opened this issue Oct 25, 2019 · 2 comments · Fixed by #78
Closed

Ability to ignore blocking calls in a static initializer #63

UgiR opened this issue Oct 25, 2019 · 2 comments · Fixed by #78
Labels
Milestone

Comments

@UgiR
Copy link

UgiR commented Oct 25, 2019

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" : "");
	}
@bsideup
Copy link
Contributor

bsideup commented Oct 25, 2019

Thanks, I will take a look.

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

bsideup added a commit that referenced this issue Jan 20, 2020
It seems that ByteBuddy's `getName()` returns class' name instead
of `<clinit>` from `getName()`.

Closes #63.
@bsideup
Copy link
Contributor

bsideup commented Jan 20, 2020

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());

@bsideup bsideup added this to the next milestone Jan 20, 2020
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 a pull request may close this issue.

2 participants