vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Guice 4.0b: CreationException hidden by Guava $ComputationException #782

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Description of the issue:
Every time my Guice mapping is borked I'm completely helpless, because I'll 
only receive a IllegalArgumentException instead of the root cause 
com.google.inject.CreationException.

The issue is, that the .toString() Method of the CreationException leads to 
another com.google.inject.internal.guava.collect.$ComputationException: 
java.lang.IllegalArgumentException on executing Errors.format()

I'm only able to read the original exception by setting a breakpoint there.

Steps to reproduce:
1. Create an illegal / missing injection with guice-servlet in Tomcat 7  and 
Guice 4 Beta
2. Build a Guice Injector in the contextInitialized() method of a 
GuiceServletContextListener
3. Instead of a meaningful CreationException you'll receive an 
IllegalArgumentException.

com.google.inject.internal.guava.collect.$ComputationException: 
java.lang.IllegalArgumentException
    at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:397)
    at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:56)
    at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:729)
    at com.google.inject.internal.Errors.formatSource(Errors.java:691)
    at com.google.inject.internal.Errors.format(Errors.java:568)
    at com.google.inject.CreationException.getMessage(CreationException.java:50)
    at foo.bar.MyGuiceServletContextListener.contextInitialized(MyGuiceServletContextListener.java:75)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1552)
    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:483)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)
    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:483)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)
    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:483)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
    at sun.rmi.transport.Transport$1.run(Transport.java:178)
    at sun.rmi.transport.Transport$1.run(Transport.java:175)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:744)

Original issue reported on code.google.com by tebu...@googlemail.com on 22 Nov 2013 at 12:54

GoogleCodeExporter commented 9 years ago
I think my error arises of a specific combination of my environment:

- I do use Java 8 EAP
- I do use Guice AOP

The issue is caused by Guice trying to give a hint about the source:

    /*if[AOP]*/
    LineNumbers lineNumbers = lineNumbersCache.get(declaringClass);

This calls com.google.inject.internal.asm.$ClassReader(byte[] bytes, int i, int 
i1) which throws an InvalidArgumentException:

  at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source:-1)
      at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source:-1)
      at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source:-1)
      at com.google.inject.internal.util.LineNumbers.<init>(LineNumbers.java:65)
      at com.google.inject.internal.util.StackTraceElements$1.apply(StackTraceElements.java:39)
      at com.google.inject.internal.util.StackTraceElements$1.apply(StackTraceElements.java:36)
      at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355)
      at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)
      at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)
      at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)
      at com.google.inject.internal.guava.collect.$ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393)
      at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:56)
      at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:729)
      at com.google.inject.internal.Errors.formatSource(Errors.java:691)
      at com.google.inject.internal.Errors.format(Errors.java:568)
      at com.google.inject.CreationException.getMessage(CreationException.java:50)
      at java.lang.Throwable.getLocalizedMessage(Throwable.java:391)
      at java.lang.Throwable.toString(Throwable.java:480)

which subsequently causes the $ComputationException completely hiding the 
original issue.

Original comment by tebu...@googlemail.com on 3 Dec 2013 at 3:55

GoogleCodeExporter commented 9 years ago
Possibly related to issue 757

Original comment by mccu...@gmail.com on 3 Dec 2013 at 4:04

GoogleCodeExporter commented 9 years ago
Thanks for the pointer. Yes - that does look very related.

Original comment by tebu...@googlemail.com on 3 Dec 2013 at 4:23

GoogleCodeExporter commented 9 years ago
I added a small patch circumventing the pending ASM failure at 
http://code.google.com/p/google-guice/issues/detail?id=757#c10

Original comment by tebu...@googlemail.com on 4 Dec 2013 at 2:18

GoogleCodeExporter commented 9 years ago
Is this bug the same as that issue?  If so,I'll close as a dup.  

Original comment by sa...@google.com on 4 Dec 2013 at 2:20

GoogleCodeExporter commented 9 years ago
I assume: In both cases failure of (LineNumbers.java:65) hides the underlying 
cause of the failure and prevents the display of Guice's informative stack 
trace. 

Please feel free to resolve as duplicate.

Original comment by tebu...@googlemail.com on 4 Dec 2013 at 2:33

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 4 Dec 2013 at 2:51