Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Could not parse MediaType #6663

@asialjim

Description

@asialjim

When GuavaAPI parse Content-Type String to GuavaMediaType, there exception happen:
Maven Dependency:

       <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>32.1.2-jre</version>
        </dependency>

Code:

        MediaType parse = MediaType.parse("multipart/form-data;charset=UTF-8;boundary =--jelsaflflksafjel");
        System.out.println(parse);

Exception:

/home/asialjim/.jdks/corretto-17.0.7/bin/java -javaagent:/home/asialjim/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/232.8660.185/lib/idea_rt.jar=43365:/home/asialjim/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/232.8660.185/bin -Dfile.encoding=UTF-8 -classpath /home/asialjim/IdeaProjects/test/guava-test/target/classes:/home/asialjim/.m2/repository/com/google/guava/guava/32.1.2-jre/guava-32.1.2-jre.jar:/home/asialjim/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/home/asialjim/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/home/asialjim/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/home/asialjim/.m2/repository/org/checkerframework/checker-qual/3.33.0/checker-qual-3.33.0.jar:/home/asialjim/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:/home/asialjim/.m2/repository/com/google/j2objc/j2objc-annotations/2.8/j2objc-annotations-2.8.jar io.github.asialjim.frame.remote.Main
Exception in thread "main" java.lang.IllegalArgumentException: Could not parse 'multipart/form-data;charset=UTF-8;boundary =--jelsaflflksafjel'
	at com.google.common.net.MediaType.parse(MediaType.java:1085)
	at io.github.asialjim.frame.remote.Main.main(Main.java:8)
Caused by: java.lang.IllegalStateException
	at com.google.common.base.Preconditions.checkState(Preconditions.java:496)
	at com.google.common.net.MediaType$Tokenizer.consumeCharacter(MediaType.java:1123)
	at com.google.common.net.MediaType.parse(MediaType.java:1063)
	... 1 more

When I delete the space charactor between 'boundary' and '=---' like this;

        MediaType parse = MediaType.parse("multipart/form-data;charset=UTF-8;boundary=--jelsaflflksafjel");
        System.out.println(parse);

Then It's worked!

By the way, This Content-Type: 'multipart/form-data;charset=UTF-8;boundary =--jelsaflflksafjel' with space charactor was generated by trip framework

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions