twilio / authy-java

Java Client for Twilio Authy Two-Factor Authentication (2FA) API
https://www.twilio.com/docs/authy/api
MIT License
65 stars 46 forks source link

Spring BeanInstantiationException for AuthyApiClient #59

Closed tcjcodes closed 5 years ago

tcjcodes commented 5 years ago

Adding AuthyApiClient causes an exception to be thrown during startup for my Spring Boot application. Is my project set up incorrectly?

Context: I only need to use the Verify API.

build.gradle uses:

    compile 'com.twilio.sdk:twilio:7.38.0' # Tried with and without this artifact
    compile 'com.authy:authy-java:1.5.0'

Spring configuration:

    @Bean
    public AuthyApiClient getAuthyApiClient() {
        return new AuthyApiClient("<valid-api-key-here>");
    }

Stack trace during startup:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getAuthyApiClient' defined in class path resource [com/zillow/identity/verification/config/TwilioConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.authy.AuthyApiClient]: Factory method 'getAuthyApiClient' threw exception; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 80
Exception Details:
  Location:
    com/authy/api/Resource.errorFromJson(Ljava/lang/String;)Lcom/authy/api/Error; @80: astore_2
  Reason:
    Type 'org/json/JSONException' (current frame, stack[0]) is not assignable to 'java/lang/RuntimeException' (stack map, stack[0])
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'com/authy/api/Resource', 'java/lang/String' }
    stack: { 'org/json/JSONException' }
  Stackmap Frame:
    bci: @80
    flags: { }
    locals: { 'com/authy/api/Resource', 'java/lang/String' }
    stack: { 'java/lang/RuntimeException' }
  Bytecode:
    0x0000000: bb00 3259 2bb7 0033 4dbb 0034 59b7 0035
    0x0000010: 4e2d 2c12 36b6 0037 b600 382c 1239 b600
    0x0000020: 37b8 003a 3604 b800 3bb8 003c 1504 ba00
    0x0000030: 3d00 00b9 003e 0200 b900 3f01 00b2 0040
    0x0000040: b600 41c0 0042 3a05 2d19 05b6 0043 2db0
    0x0000050: 4dbb 002b 5912 462c b700 2dbf          
  Exception Handler Table:
    bci [0, 79] => handler: 80
    bci [0, 79] => handler: 80
  Stackmap Table:
    same_locals_1_stack_item_extended(@80,Object[#218])

        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1276)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1133)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getPhoneVerificationHandler' defined in class path resource [com/zillow/identity/verification/config/IdentityVerificationConfiguration.class]: Unsatisfied dependency expressed through method 'getPhoneVerificationHandler' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getTwilioApiAdapter' defined in class path resource [com/zillow/identity/verification/config/TwilioConfiguration.class]: Unsatisfied dependency expressed through method 'getTwilioApiAdapter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getAuthyApiClient' defined in class path resource [com/zillow/identity/verification/config/TwilioConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.authy.AuthyApiClient]: Factory method 'getAuthyApiClient' threw exception; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 80
Exception Details:
  Location:
    com/authy/api/Resource.errorFromJson(Ljava/lang/String;)Lcom/authy/api/Error; @80: astore_2
  Reason:
    Type 'org/json/JSONException' (current frame, stack[0]) is not assignable to 'java/lang/RuntimeException' (stack map, stack[0])
May 30, 2019 3:50:42 PM org.apache.catalina.core.ContainerBase startInternal
  Current Frame:
    bci: @0
    flags: { }
SEVERE: A child container failed during start
    locals: { 'com/authy/api/Resource', 'java/lang/String' }
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939)
    stack: { 'org/json/JSONException' }
  Stackmap Frame:
    bci: @80
    flags: { }
    locals: { 'com/authy/api/Resource', 'java/lang/String' }
    stack: { 'java/lang/RuntimeException' }
  Bytecode:
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
    0x0000000: bb00 3259 2bb7 0033 4dbb 0034 59b7 0035
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    0x0000010: 4e2d 2c12 36b6 0037 b600 382c 1239 b600
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    0x0000020: 37b8 003a 3604 b800 3bb8 003c 1504 ba00
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    0x0000030: 3d00 00b9 003e 0200 b900 3f01 00b2 0040
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    0x0000040: b600 41c0 0042 3a05 2d19 05b6 0043 2db0
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    0x0000050: 4dbb 002b 5912 462c b700 2dbf          
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
  Exception Handler Table:
    bci [0, 79] => handler: 80
    bci [0, 79] => handler: 80
  Stackmap Table:
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    same_locals_1_stack_item_extended(  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
        ... 6 more
@80,Object[#218])
tcjcodes commented 5 years ago

It was a JSON issue, adding this to build.gradle fixed it:

compile 'org.json:json:20180813'