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

Setting limit throws IllegalFormatConversionException #17

Merged
merged 1 commit into from
Jan 18, 2015

Conversation

jugalps
Copy link
Contributor

@jugalps jugalps commented Jan 16, 2015

At the moment, setting the limit parameter throws the following exception:

java.util.IllegalFormatConversionException: d != java.lang.String
    at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4045)
    at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2748)
    at java.util.Formatter$FormatSpecifier.print(Formatter.java:2702)
    at java.util.Formatter.format(Formatter.java:2488)
    at java.util.Formatter.format(Formatter.java:2423)
    at java.lang.String.format(String.java:2834)
    at fr.dudie.nominatim.client.request.QueryParameterAnnotationHandler.process(QueryParameterAnnotationHandler.java:97)
    at fr.dudie.nominatim.client.request.NominatimRequest.getQueryString(NominatimRequest.java:47)
    at fr.dudie.nominatim.client.JsonNominatimClient.search(JsonNominatimClient.java:188)

The issue is that the following line of code String paramValue = serialize(paramMetadata, fieldValue, f.getName()); in QueryParameterAnnotationHandler.process(final Object o) (line 88) method converts the value of limit parameter from Integer to String.

However when you try to format the value as it is done in String.format(Locale.US, paramFormat, paramValue) in QueryParameterAnnotationHandler.process(final Object o) (line 97), it uses the %d formatter for limit specified in QueryParmeter. For instance if you set the limit to 3, the following code is executed String.format(Locale.US, "%d", "3") which results in the above exception.

At the moment, setting the limit parameter throws the following exception:
```
java.util.IllegalFormatConversionException: d != java.lang.String
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4045)
	at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2748)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2702)
	at java.util.Formatter.format(Formatter.java:2488)
	at java.util.Formatter.format(Formatter.java:2423)
	at java.lang.String.format(String.java:2834)
	at fr.dudie.nominatim.client.request.QueryParameterAnnotationHandler.process(QueryParameterAnnotationHandler.java:97)
	at fr.dudie.nominatim.client.request.NominatimRequest.getQueryString(NominatimRequest.java:47)
	at fr.dudie.nominatim.client.JsonNominatimClient.search(JsonNominatimClient.java:188)
```
The issue is that the following line of code ```String paramValue = serialize(paramMetadata, fieldValue, f.getName());``` in ```QueryParameterAnnotationHandler.process(final Object o) (line 88)``` method converts the value of limit parameter from Integer to String. 

However when you try to format the value as it is done in ```String.format(Locale.US, paramFormat, paramValue)``` in ```QueryParameterAnnotationHandler.process(final Object o) (line 97)```, it uses the %d formatter for limit specified in ```QueryParmeter```. For instance if you set the limit to 3, the following code is executed ```String.format(Locale.US, "%d", "3")``` which results in the above exception.
@jeremiehuchet
Copy link
Owner

You're right,
I did exactly the same dirty fix in NominatimReverseRequest... I'm merging and releasing fixed version quickly.

Thank you

jeremiehuchet pushed a commit that referenced this pull request Jan 18, 2015
Setting limit throws IllegalFormatConversionException
@jeremiehuchet jeremiehuchet merged commit 01c3da3 into jeremiehuchet:master Jan 18, 2015
@jeremiehuchet jeremiehuchet modified the milestone: 3.0.1 Jan 18, 2015
@jugalps jugalps deleted the patch-1 branch January 19, 2015 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants