Search plugin with custom query getting IllegalAccessError

I'm having an issue with installing a custom query in my elasticsearch plugin. For my use case, I have a custom query PayloadPhraseQuery that uses many of the other existing Lucene phrase query code.

However when I run do a search using that query I get this error. From what I find and read online, this has to do with the fact that my PayloadPhraseQuery is loaded from a different class loader from PhraseWeight, so that even if they are both in the same package, the former can't access the latter.

I don't fully understand the nuances of the JVM and Java so I might be missing something as well.

    java.lang.IllegalAccessError: class org.apache.lucene.search.PayloadPhraseQuery$1 cannot access its abstract superclass org.apache.lucene.search.PhraseWeight (org.apache.lucene.search.PayloadPhraseQuery$1 is in unnamed module of loader java.net.FactoryURLClassLoader @55bf35e5; org.apache.lucene.search.PhraseWeight is in unnamed module of loader 'app')
    	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
    	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:514)
    	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:422)
    	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:416)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:415)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    	at java.base/java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:855)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    	at org.apache.lucene.search.PayloadPhraseQuery$Builder.build(PayloadPhraseQuery.java:104)
    	at org.elasticsearch.index.query.MatchPayloadPhraseQueryBuilder.buildPhraseQuery(MatchPayloadPhraseQueryBuilder.java:145)
    	at org.elasticsearch.index.query.MatchPayloadPhraseQueryBuilder.doToQuery(MatchPayloadPhraseQueryBuilder.java:124)
    	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:103)
    	at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:324)
    	at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:308)
    	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:103)
    	at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:324)
    	at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:310)
    	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:103)
    	at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:324)
    	at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:310)
    	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:103)
    	at org.elasticsearch.index.query.NestedQueryBuilder.doToQuery(NestedQueryBuilder.java:298)
    	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:103)
    	at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:353)
    	at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:365)
    	at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:352)
    	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:844)
    	at org.elasticsearch.search.SearchService.createContext(SearchService.java:681)
    	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:631)
    	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:428)
    	at org.elasticsearch.search.SearchService.access$200(SearchService.java:135)
    	at org.elasticsearch.search.SearchService$2.lambda$onResponse$0(SearchService.java:395)
    	at org.elasticsearch.search.SearchService.lambda$runAsync$0(SearchService.java:411)
    	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44)
    	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:695)
    	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    	at java.base/java.lang.Thread.run(Thread.java:832)

What would be the suggested thing to do here? I can get around this by duplicating the abstract superclasses I need, but that solution seems hamfisted to me.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.