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

Provide API/documentation on how to allow/disallow blocking calls inside static initializer #178

Closed
simonbasle opened this issue Mar 25, 2021 · 1 comment · Fixed by #185
Labels
type/documentation A documentation update

Comments

@simonbasle
Copy link
Member

simonbasle commented Mar 25, 2021

See also #174, where a similar API/documentation should be provided for constructors.

Quoting from the above:

There is no guidance I could find on how to allow/disallow blocking in a constructor or static initializer. There is one test that shows how to do it for a static initializer but it would be nicer if it was easier to find. One option could be a dedicated method, e.g. allowBlockingCallsInsideConstructor(String classname), or otherwise provide guidance in the Javadoc on allowBlockingCallsInside and a mention on the Customizations page.

@rstoyanchev you suggested that additional methods would maybe increase the API too much, and suggested enums or varargs. How about a couple constants? Something like:

//in Blockhound.Builder class, or directly at root Blockhound.java
public static final String STATIC_INITIALIZER = "<clinit>";

//in user code
BlockHound.install(b -> b.allowBlockingCallsInside(ClassWithStaticInit.class.getName(), BlockHound.Builder.STATIC_INITIALIZER));
@simonbasle simonbasle added type/enhancement A general enhancement type/documentation A documentation update status/need-design This needs more in depth design work labels Mar 25, 2021
simonbasle added a commit that referenced this issue Mar 25, 2021
This commit introduces a STATIC_INITIALIZER constant in BlockHound, so
it becomes easier to discover that the features relying on the
`String methodName` parameter can work with `<clinit>` for static
initializer.

Additionally, this is documented in the customization examples and
used in the StaticInitTest.

Fixes #178.
@simonbasle simonbasle removed status/need-design This needs more in depth design work type/enhancement A general enhancement labels Mar 29, 2021
@simonbasle
Copy link
Member Author

going with the minimum viable solution of directly documenting <clinit> in the methods javadocs

simonbasle added a commit that referenced this issue Mar 29, 2021
This commit also mentions that constructors ("<init>") aren't
currently supported (see #174).

Fixes #178.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/documentation A documentation update
Projects
None yet
1 participant