I'm running a tomcat 8 container with 2 different webapps, 1 prod and 1 sandbox. All the classes/libs and compilation is the same with just some minor differences in the config parameters. I'm using lucene core 4.10.4 (via hibernate search). Both apps startup just fine, now after startup if I use the search on one app (let's say prod) everything works fine. The issue comes up when I then attempt to search on the second app getting this error
... Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "java.lang.invoke.MethodHandle.invokeExact()Lorg/apache/lucene/util/AttributeImpl;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/apache/lucene/util/AttributeFactory$1, and the class loader (instance of ) for resolved class, java/lang/invoke/MethodHandle, have different Class objects for the type andle.invokeExact()Lorg/apache/lucene/util/AttributeImpl; used in the signature at org.apache.lucene.util.AttributeFactory$1.createInstance(AttributeFactory.java:140) at org.apache.lucene.util.AttributeFactory$StaticImplementationAttributeFactory.createAttributeInstance(AttributeFactory.java:103) at org.apache.lucene.util.AttributeSource.addAttribute(AttributeSource.java:222) at org.apache.lucene.analysis.standard.StandardTokenizer.(StandardTokenizer.java:182) at org.apache.lucene.analysis.standard.StandardAnalyzer.createComponents(StandardAnalyzer.java:124) at org.apache.lucene.analysis.AnalyzerWrapper.createComponents(AnalyzerWrapper.java:113) at org.apache.lucene.analysis.AnalyzerWrapper.createComponents(AnalyzerWrapper.java:113) at org.apache.lucene.analysis.Analyzer.tokenStream(Analyzer.java:144) at org.hibernate.search.query.dsl.impl.Helper.getAllTermsFromText(Helper.java:74) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.getAllTermsFromText(ConnectedMultiFieldsTermQueryBuilder.java:172) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:89) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:64) ...
After the error on the second app I can still search just fine on the first one. It seems that the issue is caused when tomcat loads the needed classes for the app that I accessed the search on secondly.
Everything I've found on stackoverflow and online talks about linkage errors being due to the webapp loading the same classes from different libs or having needed classes compiled with different java versions. But in this case it's 2 different apps which is what's bizarre and they both work up until you use the search on the 2nd ap after having used it on the 1st app after a clean tomcat startup. The closest related issue I could find was this for a project named clarity.
I've been banging my head against the wall all night and can't figure out what it could be or where else to look.
After doing some more debug in the light of day I decided to update the jdk just to be 100% sure to openjdk 1.7u79 (from 1.7_05). This seems to have resolved the issue. Lucene says to use at least update 55 since there are some JVM bugs below that (I was using an earlier version of lucene up until recently). I didn't automatically jump to trying this because of the bizarre case with needing the second app to trigger the error.