Injector.getBinding(Key) throws ClassDefNotFoundError

42 views
Skip to first unread message

Gili

unread,
Jan 6, 2009, 12:08:13 PM1/6/09
to google-guice
Hi,

I just noticed that injector.getBinding(Key) throws
ClassDefNotFoundError which is unexpected. Here is the stack-trace:

java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:
2389)
at java.lang.Class.getDeclaredConstructors(Class.java:1836)
at com.google.inject.spi.InjectionPoint.forConstructorOf
(InjectionPoint.java:192)
at com.google.inject.ConstructorInjector.<init>
(ConstructorInjector.java:47)
at com.google.inject.InjectorImpl$5.create(InjectorImpl.java:
753)
at com.google.inject.InjectorImpl$5.create(InjectorImpl.java:
749)
at com.google.inject.internal.FailableCache$1.create
(FailableCache.java:32)
at com.google.inject.internal.ReferenceCache.create
(ReferenceCache.java:54)
at
com.google.inject.internal.AbstractReferenceCache.internalCreate
(AbstractReferenceCache.java:59)
at com.google.inject.internal.AbstractReferenceCache.get
(AbstractReferenceCache.java:116)
at com.google.inject.internal.ReferenceCache.get
(ReferenceCache.java:28)
at com.google.inject.internal.FailableCache.get
(FailableCache.java:43)
at com.google.inject.InjectorImpl$LateBoundConstructor.bind
(InjectorImpl.java:457)
at com.google.inject.ClassBindingImpl.initialize
(ClassBindingImpl.java:52)
at com.google.inject.InjectorImpl.initializeBinding
(InjectorImpl.java:347)
at com.google.inject.InjectorImpl.createJustInTimeBinding
(InjectorImpl.java:639)
at
com.google.inject.InjectorImpl.createJustInTimeBindingRecursive
(InjectorImpl.java:584)
at com.google.inject.InjectorImpl.getJustInTimeBinding
(InjectorImpl.java:179)
at com.google.inject.InjectorImpl.getBindingOrThrow
(InjectorImpl.java:139)
at com.google.inject.InjectorImpl.getBinding(InjectorImpl.java:
116)
at com.google.inject.InjectorImpl.getBinding(InjectorImpl.java:
71)

I just wanted to run this by you. Is this the best we can do or do we
want to wrap this in ConfigurationException or something? I understand
this is tricky given the fact that an Error is being thrown.

Gili

Gili

unread,
Jan 6, 2009, 12:10:42 PM1/6/09
to google-guice
I forgot to mention the context. What is going on is that my
application tries to inject a class called MultiPartReader, which in
turn depends upon JavaMail which is missing. My application asks Guice
"can you inject MultiPartReader?" and it replies with
NoClassDefFoundError which is a bit unexpected. I am somewhat
expecting it to answer "no, and here's why" not throw an exception
that indicates the checking process itself failed.

Gili

limpb...@gmail.com

unread,
Jan 6, 2009, 4:34:46 PM1/6/09
to google-guice
On Jan 6, 9:10 am, Gili <gili.tzab...@gmail.com> wrote:
> I forgot to mention the context. What is going on is that my
> application tries to inject a class called MultiPartReader, which in
> turn depends upon JavaMail which is missing. My application asks Guice
> "can you inject MultiPartReader?" and it replies with
> NoClassDefFoundError which is a bit unexpected. I am somewhat
> expecting it to answer "no, and here's why" not throw an exception
> that indicates the checking process itself failed.

Guice doesn't catch Errors, or attempt to recover from them. From the
Error Javadoc:
An Error is a subclass of Throwable that indicates serious problems
that a reasonable application should not try to catch.

This is partly due to the fact that Guice is a reasonable application.

Gili Tzabari

unread,
Jan 6, 2009, 4:46:45 PM1/6/09
to google...@googlegroups.com

I don't necessarily disagree. I just found the behavior a bit
surprising which is why I wanted to run it by you. Anyway, thanks for
the reply :)

Gili
Reply all
Reply to author
Forward
0 new messages