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!
Bridge
public class ArticleVisibilityBridge implements TypeBridge<Article> {
private final IndexFieldReference<String> visibilityField;
public ArticleVisibilityBridge(
IndexFieldReference<String> visibilityField
) {
this.visibilityField = visibilityField;
}
@Override
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);
}
}
Binder
public class VisibilityBinder implements TypeBinder {
@Override
public void bind(final TypeBindingContext context) {
context.dependencies()
.use( "manufacturer" )
.use( "category" );
final IndexFieldReference<String> visibilityField =
context
.indexSchemaElement()
.field("visibility", IndexFieldTypeFactory::asString)
.toReference();
context.bridge(
Article.class,
// Potential resource leak: '<unassigned Closeable value>' may not be closed
new ArticleVisibilityBridge(visibilityField)
);
}
}