最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rest - Ambiguous method overloading for method java.util.LinkedHashMap#leftShift - Stack Overflow

programmeradmin4浏览0评论

I have a method that makes api call:

public def getInfo(String A, String B, String C, String D, String E) {
        def response = null;
        def requestHeaders = ['A': A, 'B' : B]
        requestHeaders << headers

        Map uriVariables = [C : C, D : D, start: 1, end: 10, E: E]
        try {
            response = restMethod.get(getInfo, uriVariables, requestHeaders, [:])
            if(!response) {
                return null;
            }
        } catch (e) {
            logger.error("Error getting data", e)
        }
        return response?.data ? response?.data : null
    }

Then I wrote another function to test that api call locally from SwaggerUI

@CrossOrigin
    @RequestMapping(method = RequestMethod.GET, path = '/getInfo')
    def getInfoTest(@RequestHeader('A') String A, @RequestHeader('B') String B, @RequestHeader('C') String C, @RequestHeader('D') String D, @RequestHeader('E') String E) {
    
        infoResponse = InfoRestClient.getInfo(A, B, C, D, E)
        return infoResponse
    }

Somehow when I ran the call, I got this error:

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.util.LinkedHashMap#LleftShift.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
    [interface java.util.Map]
    [interface java.util.Map$Entry]

I tried to work around with the parameters for the getInfoTest, but it all returns to the same error. I've checked and some older posts say this error is caused because of different functions with the same name, but I only got 1 function with such name. Has anyone got similar issue and how did you solve it? Thank you so much in advance!

I have a method that makes api call:

public def getInfo(String A, String B, String C, String D, String E) {
        def response = null;
        def requestHeaders = ['A': A, 'B' : B]
        requestHeaders << headers

        Map uriVariables = [C : C, D : D, start: 1, end: 10, E: E]
        try {
            response = restMethod.get(getInfo, uriVariables, requestHeaders, [:])
            if(!response) {
                return null;
            }
        } catch (e) {
            logger.error("Error getting data", e)
        }
        return response?.data ? response?.data : null
    }

Then I wrote another function to test that api call locally from SwaggerUI

@CrossOrigin
    @RequestMapping(method = RequestMethod.GET, path = '/getInfo')
    def getInfoTest(@RequestHeader('A') String A, @RequestHeader('B') String B, @RequestHeader('C') String C, @RequestHeader('D') String D, @RequestHeader('E') String E) {
    
        infoResponse = InfoRestClient.getInfo(A, B, C, D, E)
        return infoResponse
    }

Somehow when I ran the call, I got this error:

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.util.LinkedHashMap#LleftShift.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
    [interface java.util.Map]
    [interface java.util.Map$Entry]

I tried to work around with the parameters for the getInfoTest, but it all returns to the same error. I've checked and some older posts say this error is caused because of different functions with the same name, but I only got 1 function with such name. Has anyone got similar issue and how did you solve it? Thank you so much in advance!

Share Improve this question edited Feb 17 at 6:03 cfrick 37.1k7 gold badges60 silver badges74 bronze badges asked Feb 17 at 1:34 jasperjasper 435 bronze badges 2
  • Please do not use images with text. Readers can then search the text or run the code to reproduce your issue. Also add the full stack-trace and correlate the line numbers with your code. – cfrick Commented Feb 17 at 6:07
  • Got it, thanks! – jasper Commented Feb 17 at 12:39
Add a comment  | 

1 Answer 1

Reset to default 0

.leftShift() is called when you use << in your code. So the offending code is requestHeaders << headers and the error states, that you are calling it with a null argument (which fails in the polymorphic dispatch, hence the error).

Given, that adding "nothing" to your map, will not do much, you can prevent that error by making the addition conditional. E.g.

if (headers) {
    requestHeaders << headers
}
发布评论

评论列表(0)

  1. 暂无评论