Java - java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions

se7entyse7en picture se7entyse7en · Aug 26, 2015 · Viewed 12.2k times · Source

I'm working on an extension for druid that uses jclouds for Rackspace Cloud Files and I encountered a problem with Google guice and I'm not very confident with Java.

I already saw this question, but it doesn't seem that there's a conflict in guice versions.

This is the code that is being executed:

@Provides
@LazySingleton
public CloudFilesApi getCloudFilesApi(final CloudFilesAccountConfig config) {
    log.info("Provider: " + config.getProvider());
    log.info("Username: " + config.getUserName());
    log.info("Api key: " + config.getApiKey());
    ContextBuilder cb = ContextBuilder.newBuilder(config.getProvider());
    log.info("Context builder built.");
    cb = cb.credentials(config.getUserName(), config.getApiKey());
    log.info("Context builder authenticated.");
    CloudFilesApi cfa = cb.buildApi(CloudFilesApi.class);
    log.info("Cloud Files Api built.");
    return cfa;
}

and this is the log:

2015-08-26T13:15:53,663 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.druid.storage.cloudfiles.CloudFilesAccountConfig] from props[druid.cloudfiles.] as [io.druid.storage.cloudfiles.CloudFilesAccountConfig@32d70ac]
2015-08-26T13:15:53,664 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Provider: rackspace-cloudfiles-us
2015-08-26T13:15:53,664 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Username: <value>
2015-08-26T13:15:53,665 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Api key: <value>
2015-08-26T13:15:54,425 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder built.
2015-08-26T13:15:54,425 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder authenticated.
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:

1) Error injecting constructor, java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
  at io.druid.guice.FireDepartmentsProvider.<init>(FireDepartmentsProvider.java:41)
  while locating io.druid.guice.FireDepartmentsProvider
  at io.druid.guice.RealtimeModule.configure(RealtimeModule.java:79)
  while locating java.util.List<io.druid.segment.realtime.FireDepartment>
    for parameter 0 at io.druid.segment.realtime.RealtimeMetricsMonitor.<init>(RealtimeMetricsMonitor.java:42)
  while locating io.druid.segment.realtime.RealtimeMetricsMonitor
  at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
  at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
  while locating com.metamx.metrics.MonitorScheduler
  at io.druid.server.metrics.MetricsModule.configure(MetricsModule.java:63)
  while locating com.metamx.metrics.MonitorScheduler annotated with @com.google.inject.name.Named(value=ForTheEagerness)

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448)
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
        at com.google.inject.Guice.createInjector(Guice.java:96)
        at com.google.inject.Guice.createInjector(Guice.java:73)
        at com.google.inject.Guice.createInjector(Guice.java:62)
        at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:412)
        at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:55)
        at io.druid.cli.ServerRunnable.run(ServerRunnable.java:37)
        at io.druid.cli.Main.main(Main.java:91)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
        at org.nnsoft.guice.rocoto.configuration.ConfigurationModule.configure(ConfigurationModule.java:64)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:230)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.spi.Elements.getElements(Elements.java:94)
        at org.nnsoft.guice.rocoto.Rocoto.expandVariables(Rocoto.java:52)
        at org.nnsoft.guice.rocoto.Rocoto.expandVariables(Rocoto.java:47)
        at org.jclouds.config.BindPropertiesToExpandedValues.configure(BindPropertiesToExpandedValues.java:45)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:230)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
        at com.google.inject.Guice.createInjector(Guice.java:96)
        at com.google.inject.Guice.createInjector(Guice.java:84)
        at org.jclouds.ContextBuilder.expandProperties(ContextBuilder.java:382)
        at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:317)
        at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:644)
        at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:636)
        at io.druid.storage.cloudfiles.CloudFilesStorageDruidModule.getCloudFilesApi(CloudFilesStorageDruidModule.java:68)
        [...]

I also do not understand why the string "Cloud Files Api built." is not being printed.

The classpath is the lib directory:

user@host:/opt/druid# ls lib | grep guice
guice-4.0-beta.jar
guice-assistedinject-3.0.jar
guice-multibindings-4.0-beta.jar
guice-servlet-4.0-beta.jar
jersey-guice-1.17.1.jar

UPDATE 1

Maybe is related to this issue? I'm gonna try to downgrade to Google guice to 3.0.

UPDATE 2

I downgraded Google guice to 3.0, now I have:

user@host:/opt/druid# ls lib | grep guice
guice-3.0.jar
guice-assistedinject-3.0.jar
guice-multibindings-3.0.jar
guice-servlet-3.0.jar
jersey-guice-1.17.1.jar

and now the error changed:

    2015-08-26T14:22:06,978 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.druid.storage.cloudfiles.CloudFilesAccountConfig] from props[druid.cloudfiles.] as [io.druid.storage.cloudfiles.CloudFilesAccountConfig@273f1cb3]
2015-08-26T14:22:06,979 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Provider: rackspace-cloudfiles-us
2015-08-26T14:22:06,980 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Username: viralizecloud
2015-08-26T14:22:06,980 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Api key: df185fe598ed99ef27a247a21b578c3a
2015-08-26T14:22:07,782 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder built.
2015-08-26T14:22:07,783 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder authenticated.
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:

1) Error injecting constructor, java.lang.VerifyError: Cannot inherit from final class
  at io.druid.guice.FireDepartmentsProvider.<init>(FireDepartmentsProvider.java:41)
  while locating io.druid.guice.FireDepartmentsProvider
  at io.druid.guice.RealtimeModule.configure(RealtimeModule.java:79)
  while locating java.util.List<io.druid.segment.realtime.FireDepartment>
    for parameter 0 at io.druid.segment.realtime.RealtimeMetricsMonitor.<init>(RealtimeMetricsMonitor.java:42)
  while locating io.druid.segment.realtime.RealtimeMetricsMonitor
  at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
  at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
  while locating com.metamx.metrics.MonitorScheduler
  at io.druid.server.metrics.MetricsModule.configure(MetricsModule.java:63)
  while locating com.metamx.metrics.MonitorScheduler annotated with @com.google.inject.name.Named(value=ForTheEagerness)

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
        at com.google.inject.Guice.createInjector(Guice.java:95)
        at com.google.inject.Guice.createInjector(Guice.java:72)
        at com.google.inject.Guice.createInjector(Guice.java:62)
        at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:412)
        at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:55)
        at io.druid.cli.ServerRunnable.run(ServerRunnable.java:37)
        at io.druid.cli.Main.main(Main.java:91)
Caused by: java.lang.VerifyError: Cannot inherit from final class
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
        at java.lang.Class.getDeclaredConstructors(Class.java:1914)
        at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
        at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
        at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:629)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:845)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
        at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
        at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
        at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
        at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
        at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
        at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:133)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
        at com.google.inject.Guice.createInjector(Guice.java:95)
        at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:402)
        at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:326)
        at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:644)
        at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:636)
        at io.druid.storage.cloudfiles.CloudFilesStorageDruidModule.getCloudFilesApi(CloudFilesStorageDruidModule.java:68)
        [...]

Answer

dimo414 picture dimo414 · Apr 4, 2017

Looking at your classpath:

guice-4.0-beta.jar
guice-assistedinject-3.0.jar

You're using Guice v4.0b but v3.0 of the AssistedInject Guice extension. You should upgrade them all at once from version to version. It sounds like you dropped everything back to v3.0, which works, but you could instead upgrade the AssistedInject extension.