Stefan: How do I tell if I'm in an OSGi environment or not? I don't know much about OSGi and I don't think I am using it (at least, I haven't done anything specific in the application to turn on OGSi). I just thought OSGI might be the issue because it looked like a classloader issue and I saw osgi in the package name. Is there any harm in using the DefaultLdapCodecService over the StandaloneLdapApiService even if I'm not in an OSGi environment? What's the difference?
Emmanuel: thanks for the fix, I'm still trying to test it; running into some mvn versioning issues. Is there a guide for what version of directory server I need to use with which version of the ldap api? I'm using M15 directory server versions and M30-SNAPSHOT ldap apis. With this, I get NoSuchMethodError on the functions you added (because the api-ldap-codec-core gets pulled in as M20 from a server dependency); if I change the order of the dependencies I get java.lang.NoClassDefFoundError: org/apache/directory/api/ldap/schemaloader/SchemaEntityFactory. Greg On Thu, Apr 23, 2015 at 10:56 PM, Stefan Seelmann <[email protected]> wrote: > In an OSGi environment the StandaloneLdapApiService (module > api-ldap-codec-standalone) should not be used at all. > > Instead the bundle activator > org.apache.directory.api.ldap.codec.osgi.DefaultActivator creates and > registers the DefaultLdapCodecService. > > Kind Regards, > Stefan > > On 04/24/2015 01:25 AM, Gregory Chanan wrote: > > I wanted to upgrade the LDAP API version of my application to pick up > > https://issues.apache.org/jira/browse/DIRAPI-219. Unfortunately, I hit > > some problems, namely: > > > > java.lang.IllegalAccessError: tried to access field > > > org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService.controlFactories > > from class > > org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService > > > > I tracked this down to upgrading from M21 to M22 (i.e. my code works with > > M21, doesn't work with M22), where it looks like DefaultLdapCodecService > is > > now a superclass of StandaloneLdapApiService. StackOverflow suggests > this > > can be caused by different class loaders: > > > http://stackoverflow.com/questions/3386662/illegalaccesserror-accessing-a-protected-method/3387520#3387520 > > > > Has anyone seen this? Is there a suggested workaround? > > > > FWIW I was able to get my application to work by adding: > > > > DefaultLdapCodecService dlcs = new DefaultLdapCodecService(); > > LdapApiServiceFactory.initialize(dlcs); > > before the problematic line: > > ds = new DefaultDirectoryService(); > > but I'm not sure what the implication of using DefaultLdapCodecService > > compared to StandaloneLdapApiService (which is what gets loaded if you > > don't manually initialize the LdapApiServiceFactory. > > > > The application is Hadoop MiniKdc, see here: > > > https://github.com/apache/hadoop/blob/e3496499ecb8d220fba99dc5ed4c99c8f9e33bb1/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java#L324 > > > > Here's the entire stack trace (this is running in maven surefire): > > java.lang.IllegalAccessError: tried to access field > > > org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService.controlFactories > > from class > > org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService > > at > > > org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService.<init>(StandaloneLdapApiService.java:148) > > at > > > org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService.<init>(StandaloneLdapApiService.java:142) > > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) > > at > > > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) > > at > > > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > > at java.lang.reflect.Constructor.newInstance(Constructor.java:525) > > at java.lang.Class.newInstance0(Class.java:374) > > at java.lang.Class.newInstance(Class.java:327) > > at > > > org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory.initialize(LdapApiServiceFactory.java:127) > > at > > > org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory.getSingleton(LdapApiServiceFactory.java:89) > > at > > > org.apache.directory.server.core.DefaultDirectoryService.<init>(DefaultDirectoryService.java:150) > > at > > org.apache.hadoop.minikdc.MiniKdc.initDirectoryService(MiniKdc.java:335) > > at org.apache.hadoop.minikdc.MiniKdc.start(MiniKdc.java:327) > > at > > > org.apache.hadoop.minikdc.KerberosSecurityTestcase.startMiniKdc(KerberosSecurityTestcase.java:49) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > > at > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > > at java.lang.reflect.Method.invoke(Method.java:601) > > at > > > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) > > at > > > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) > > at > > > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) > > at > > > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) > > at > > > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) > > at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) > > at > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) > > at > > > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) > > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) > > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) > > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) > > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) > > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) > > at org.junit.runners.ParentRunner.run(ParentRunner.java:309) > > at > > > org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:254) > > at > > > org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:149) > > at > > > org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124) > > at > > > org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200) > > at > > > org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153) > > at > > org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) > > > >
