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!
- 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
1 Answer
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
}