Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

java.util.UnknownFormatConversionException #1734

Open

Description

@linwoain

I use rest like this:

@Rest(rootUrl = "http://xxx.com",converters = GsonHttpMessageConverter.class)
public interface APIService {

    @Get("/app/api/json.php?param={%22limit_a%22:0,%22limit_b%22:10,%22flag%22:6,%22m%22:101}")
    MyBean getObj();
}
Error:(16, 12) 错误: Something went wrong: Unexpected error in AndroidAnnotations 4.0.0!
You should check if there is already an issue about it on https://github.com/excilys/androidannotations/search?q=java.util.UnknownFormatConversionException&type=Issues
If none exists, please open a new one with the following content and tell us if you can reproduce it or not. Don't forget to give us as much information as you can (like parts of your code in failure).
Java version: javac 1.8.0_40
Javac processors options:
Stacktrace: java.util.UnknownFormatConversionException: Conversion = 'l'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
at java.util.Formatter.parse(Formatter.java:2560)
at java.util.Formatter.format(Formatter.java:2501)
at java.util.Formatter.format(Formatter.java:2455)
at java.lang.String.format(String.java:2928)
at org.androidannotations.ElementValidation.addError(ElementValidation.java:58)
at org.androidannotations.ElementValidation.addError(ElementValidation.java:53)
at org.androidannotations.rest.spring.helper.RestSpringValidatorHelper.urlVariableNamesExistInParameters(RestSpringValidatorHelper.java:389)
at org.androidannotations.rest.spring.handler.RestMethodHandler.validate(RestMethodHandler.java:74)
at org.androidannotations.rest.spring.handler.GetHandler.validate(GetHandler.java:33)
at org.androidannotations.handler.BaseAnnotationHandler.validate(BaseAnnotationHandler.java:65)
at org.androidannotations.internal.process.ModelValidator.validate(ModelValidator.java:70)
at org.androidannotations.internal.AndroidAnnotationProcessor.validateAnnotations(AndroidAnnotationProcessor.java:216)
at org.androidannotations.internal.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:174)
at org.androidannotations.internal.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:126)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:45)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:101)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:50)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:157)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:139)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:93)
at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
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:497)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory

Activity

  1. dodgex commented on Mar 21, 2016

    @dodgex
    Member

    this is two issues in one run.

    1. the exception is due to a bug in AA where a error message format is invalid
    2. you get this error message as you apparently try to have json in your urls query parameter. but in AA the {} is uesed to detect an url variable. therefore your json string is assumed to be an url varialbe (and as your method does not have a parameter the error should have been printed - but caused this exception due to the AA bug)
  2. dodgex commented on Mar 21, 2016

    @dodgex
    Member

    correction to 1) due to the content of your json and therefore the with {} detected url variable name the json (more precise the %22 inside) causes the exception due to the use of String.format() with that string being part of the format parameter...

    @WonderCsabo any idea if we can fix that?

  3. WonderCsabo commented on Mar 21, 2016

    @WonderCsabo
    Member

    Well, there are two considerations here:

    1. Currently, we do not allow {}s in the url, but sometimes they are not url variables, as we seen here. Maybe we should not validate from this direction? Maybe we should check what Retfofit does.
    2. The logger should escape the incoming strings, this is definitely an issue.
  4. dodgex commented on Mar 21, 2016

    @dodgex
    Member

    it cant escape the string in this case as it is concatenated to the String that is used as format parameter.

  5. WonderCsabo commented on Mar 21, 2016

    @WonderCsabo
    Member

    Yes, we should introduce some new api for that.

  6. dodgex commented on Mar 21, 2016

    @dodgex
    Member

    it would be good to have an override of addError that allows to pass parameters to be passed to String.format be used to do the formatting

  7. WonderCsabo commented on Mar 21, 2016

    @WonderCsabo
    Member

    Yes, we should add an overload, i agree!

  8. dodgex commented on Mar 21, 2016

    @dodgex
    Member

    yeah... overload is what i meant no idea why i wrote override. sorry :D

  9. gauravsak commented on Dec 30, 2016

    @gauravsak

    @WonderCsabo @dodgex @linwoain Is this bug supposed to be an enhancement then? Could you please mark it accordingly? Thanks!

  10. WonderCsabo commented on Dec 30, 2016

    @WonderCsabo
    Member

    @gauravsak i labelled this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions