Skip to content

Commit

Permalink
Disable MethodHandles in HSearch, even with GraalVM 21+
Browse files Browse the repository at this point in the history
It causes weird errors when mass indexing, probably because
the MethodHandles implementation in native mode is not completely
thread-safe.

For example:

Entities that could not be indexed correctly:
Person#212 : org.hibernate.search.util.common.SearchException:
HSEARCH900005: Exception while invoking 'private java.lang.Long
io.quarkus.it.hibernate.search.elasticsearch.search.Person.id' on
'io.quarkus.it.hibernate.search.elasticsearch.search.Person@33be79fb'.
...
Caused by: java.lang.ClassCastException:
io.quarkus.it.hibernate.search.elasticsearch.search.Address cannot be
cast to io.quarkus.it.hibernate.search.elasticsearch.search.Person
  • Loading branch information
yrodiere authored and gsmet committed Apr 14, 2021
1 parent 5b2a5d2 commit 13d09a2
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,9 @@ public void contributeBootProperties(BiConsumer<String, Object> propertyCollecto
@Override
public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
BiConsumer<String, Object> propertyCollector) {
Version graalVMVersion = Version.getCurrent();
final boolean isAOT = Boolean.getBoolean("com.oracle.graalvm.isaot");
boolean isGraalVM20OrBelow = isAOT && graalVMVersion.compareTo(GRAAL_VM_VERSION_21) < 0;
HibernateOrmIntegrationBooter booter = HibernateOrmIntegrationBooter.builder(metadata, bootstrapContext)
.valueReadHandleFactory(
// GraalVM 20 or below doesn't support method handles
isGraalVM20OrBelow ? ValueReadHandleFactory.usingJavaLangReflect()
// GraalVM 21+ and OpenJDK can handle the default (method handles)
: null)
// MethodHandles don't work at all in GraalVM 20 and below, and seem unreliable on GraalVM 21
.valueReadHandleFactory(ValueReadHandleFactory.usingJavaLangReflect())
.build();
booter.preBoot(propertyCollector);
}
Expand Down

0 comments on commit 13d09a2

Please sign in to comment.