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!

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. Commented Feb 17 at 6:07
  • Got it, thanks! Commented Feb 17 at 12:39

1 Answer 1

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
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer! I tried different scenarios: hard coded the values in headers for the test, and input the value from SwaggerUI. So I don’t understand why it’s null
This is the answer for your groovy problem - if this leads to a different problem create a new question or refine your question. Ideally provide a minimal reproducible example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.