Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible Return Types when returning generics in Javanica #1328

Closed
VaultB0Y opened this issue Aug 22, 2016 · 4 comments
Closed

Incompatible Return Types when returning generics in Javanica #1328

VaultB0Y opened this issue Aug 22, 2016 · 4 comments

Comments

@VaultB0Y
Copy link

I am trying to introduce the Hystrix Javanica in the Spring Resttemplate.
I tried to add the hystrix command to getForEntity, but it throws an exception:

com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: Incompatible return types. Command method: public org.springframework.http.ResponseEntity hystrix.HystrixCircuitBreakerRestTemplate.getForEntity(java.lang.String,java.lang.Class,java.lang.Object[]) throws org.springframework.web.client.RestClientException, fallback method: public org.springframework.http.ResponseEntity hystrix.HystrixCircuitBreakerRestTemplate.getForEntityFallback(java.lang.String,java.lang.Class,java.lang.Object[]) throws org.springframework.web.client.RestClientException. Hint: 
    at com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.validateReturnType(FallbackMethod.java:132)
    at com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.validateReturnType(FallbackMethod.java:111)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.setFallbackMethod(HystrixCommandAspect.java:292)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.access$300(HystrixCommandAspect.java:62)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$MetaHolderFactory.metaHolderBuilder(HystrixCommandAspect.java:155)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$CommandMetaHolderFactory.create(HystrixCommandAspect.java:236)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$MetaHolderFactory.create(HystrixCommandAspect.java:145)
    at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
...
public class HystrixCircuitBreakerRestTemplate extends RestTemplate {
    @Override
    @HystrixCommand(fallbackMethod = "getForEntityFallback", 
    commandProperties = { 
        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "10"),
        @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
        @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "3"),
        @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10"),
        @HystrixProperty(name = "circuitBreaker.forceOpen", value = "true")
    }) 
    public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... urlVariables) throws RestClientException {
        System.out.println("HystrixCircuitBreakerRestTemplate: getForEntity");
        return super.getForEntity(url, responseType, urlVariables);
    }

    public <T> ResponseEntity<T> getForEntityFallback(String url, Class<T> responseType, Object... urlVariables) throws RestClientException {
        System.out.println("HystrixCircuitBreakerRestTemplate: Fallback");
        return null;
    }
}

If I remove the fallbackMethod in the HystrixCommand, it is working fine. It doesn't work with the fallbackMethod. It's strange that the two return types are the same but throws incompatible return type exception. I suspect there is something wrong with the generics.

@mattrjacobs
Copy link
Contributor

@VaultB0Y off the top of my head I would expect that to work as well. Perhaps something about generics aren't working properly.

@dmgcodevil - Are you able to take a look?

@dmgcodevil
Copy link
Contributor

Hi, yes, it's definitely a bug, I'm going to fix couple bugs on this weekend and this one too

@mattrjacobs
Copy link
Contributor

Fixed in #1341

@rajeshrudra007
Copy link

I am adding Hystrix fallback method, getting some error:Please find below errors and let me know how can i resolve this issue.
Producer code

Command method: public org.springframework.http.ResponseEntity com.elearning.course.controller.CourseController.listOfCoursedetails();
Fallback method: public com.elearning.course.model.Course com.elearning.course.controller.CourseController.getDataFallback();
Hint: Different size of types variables.
Command type literals size = 3: [org.springframework.http.ResponseEntity<java.util.List<com.elearning.course.model.Course>>, java.util.List<com.elearning.course.model.Course>, class com.elearning.course.model.Course]
Fallback type literals size = 1: [class com.elearning.course.model.Course]

Command type literal pos: unknown; Fallback type literal pos: unknown] with root cause

com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: Incompatible return types.
Command method: public org.springframework.http.ResponseEntity com.elearning.course.controller.CourseController.listOfCoursedetails();
Fallback method: public com.elearning.course.model.Course com.elearning.course.controller.CourseController.getDataFallback();
Hint: Different size of types variables.
Command type literals size = 3: [org.springframework.http.ResponseEntity<java.util.List<com.elearning.course.model.Course>>, java.util.List<com.elearning.course.model.Course>, class com.elearning.course.model.Course]
Fallback type literals size = 1: [class com.elearning.course.model.Course]

Command type literal pos: unknown; Fallback type literal pos: unknown

Client Code error

org.springframework.web.client.HttpServerErrorException: 500 null
Exception in thread "main" java.lang.NullPointerException
at com.elearning.course.client.CourseConsumerClient.getCourses(CourseConsumerClient.java:43)
at com.elearning.course.WebClientMicroserviceServerApplication.main(WebClientMicroserviceServerApplication.java:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants