Closable causes warning in Hibernate Search 6

While trying to create class bridge in Hibernate Search 6, there is a warning I don’t know to handle:

Potential resource leak: ‘<unassigned Closeable value>’ may not be closed

It is attached to this line (also this line is provided with the whole binder below):

new ArticleVisibilityBridge(visibilityField)

How can I close it? Should I use try-with? Leaking resources is the last thing I want for my app to have. Please help!


public class ArticleVisibilityBridge implements TypeBridge<Article> {
	private final IndexFieldReference<String> visibilityField;

	public ArticleVisibilityBridge(
		IndexFieldReference<String> visibilityField
	) {
		this.visibilityField  = visibilityField;

	public void write(
		DocumentElement target,
		Article bridgedElement,
		TypeBridgeWriteContext context
	) {
		String visibility;
		if (ArticleIndexingUtil.visible(bridgedElement)) {
			visibility = "Visible";
		else {
			visibility = "NotVisible";
		target.addValue(this.visibilityField, visibility);


public class VisibilityBinder implements TypeBinder {
	public void bind(final TypeBindingContext context) {
			.use( "manufacturer" )
			.use( "category" );

		final IndexFieldReference<String> visibilityField =
				.field("visibility", IndexFieldTypeFactory::asString)

// Potential resource leak: '<unassigned Closeable value>' may not be closed
			new ArticleVisibilityBridge(visibilityField)



That’s a false positive. Hibernate Search is responsible for closing bridges, you are not.

Just use @SuppressWarnings or something if that warning bothers you.

1 Like